【发布时间】:2012-01-14 17:36:01
【问题描述】:
public class BobDatabase extends SQLiteOpenHelper{
private static final String DATABASE_NAME = "bob.db";
private static final int DATABASE_VERSION = 1;
public static final String DEFAULT_PROFILE = "default_profile";
public BobDatabase(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database)
{
createProfileTable(database);
createTimeTable(database);
createEventTable(database);
createLocationTable(database);
}
/**
* Creates a table for Profile objects, executes the string create_profile_table_sql
* contained within strings.xml
* @param database
*/
public void createProfileTable(SQLiteDatabase database)
{
database.execSQL(Resources.getSystem().getString(R.string.create_profile_table_sql));
}}
我收到此错误
01-14 12:20:57.591:E/AndroidRuntime(1825):原因:android.content.res.Resources$NotFoundException:字符串资源 ID #0x7f040003
导致错误的代码是 createProfileTable 中的单行,Resources.getSystem().getString(R.string.create_profile_table_sql) 如果我使用类变量来保存 Context 并执行context.getString(R.string.create_profile_table_sql) 我没有收到任何错误,但我不想这样做,因为我想避免内存泄漏,并且据我所知这应该可以工作。知道发生了什么吗?
【问题讨论】:
-
这并不能真正回答您的问题,但字符串资源通常用于用户可显示的字符串(因此,如果您愿意,以后可以提供不同的语言)。在这种情况下,定义一个常量字符串来定义您的 create 语句就可以了。
标签: java android eclipse sqliteopenhelper