我第一次在这里问问题,所以要温柔,大声笑。
反正。我一直在使用 Android,我的最新版本运行完美。直到昨天,当 IT 给我一个新工作站时。自从有了这个新工作站后,我不断收到以下错误:
04-11 17:34:53.282: E/AndroidRuntime(789): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.blueharvest/com.example.blueharvest.SettingsActivity}: java.lang.IllegalStateException: getDatabase called recursively
如果有帮助,我将在虚拟设备中运行它,使用平台 4.2.2 和 API 级别 17。
我真的希望有人能对这个错误有所了解,这样我就可以停止扯头发了,哈哈。
如果需要任何其他信息,请告诉我。
非常感谢,
布拉德。
编辑:添加了更多的 logcat
04-11 19:25:08.668: E/AndroidRuntime(2748): FATAL EXCEPTION: main
04-11 19:25:08.668: E/AndroidRuntime(2748): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.blueharvest/com.example.blueharvest.SettingsActivity}: java.lang.IllegalStateException: getDatabase called recursively
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.os.Looper.loop(Looper.java:137)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-11 19:25:08.668: E/AndroidRuntime(2748): at java.lang.reflect.Method.invokeNative(Native Method)
04-11 19:25:08.668: E/AndroidRuntime(2748): at java.lang.reflect.Method.invoke(Method.java:511)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-11 19:25:08.668: E/AndroidRuntime(2748): at dalvik.system.NativeStart.main(Native Method)
04-11 19:25:08.668: E/AndroidRuntime(2748): Caused by: java.lang.IllegalStateException: getDatabase called recursively
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:204)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.example.blueharvest.DatabaseHandler.setDefaultLabel(DatabaseHandler.java:90)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.example.blueharvest.DatabaseHandler.onCreate(DatabaseHandler.java:82)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.example.blueharvest.DatabaseHandler.populateFields(DatabaseHandler.java:196)
04-11 19:25:08.668: E/AndroidRuntime(2748): at com.example.blueharvest.SettingsActivity.onCreate(SettingsActivity.java:45)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.Activity.performCreate(Activity.java:5104)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-11 19:25:08.668: E/AndroidRuntime(2748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-11 19:25:08.668: E/AndroidRuntime(2748): ... 11 more
编辑:添加了导致错误的代码。setDefaultLabel() 是罪魁祸首。
@Override
public void onCreate(SQLiteDatabase db) {
// Create tables
db.execSQL(CREATE_CATEGORIES_TABLE);
db.execSQL(CREATE_CHRGDATA_TABLE);
db.execSQL(CREATE_SETTINGS_TABLE);
setDefaultLabel();
}
/**
*
*/
public void setDefaultLabel() {
// create default label
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, "Default");
db.insert(TABLE_LABELS, null, values);
}