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.getString(R.string.create_profile_table_sql)我没有收到任何错误,但我不想这样做,因为我想避免内存泄漏,并且根据我所知道的,这应该可行。知道发生了什么吗?
根据 Android 文档,Resources.getSystem()
仅提供系统级资源,而不提供应用程序级资源(例如 strings.xml 文件中的资源)。
http://developer.android.com/reference/android/content/res/Resources.html#getSystem() http://developer.android.com/reference/android/content/res/Resources.html#getSystem()
如果您确实想以这种方式检索字符串,请尝试使用应用程序的上下文,或者采纳我在问题评论中的建议。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)