我尝试从RecipesActivity.java 启动AddEditRecipesActivity.java。在 RecipesActivity 中有一个来自数据表的数据列表。通过按RecipesActivity 中的添加按钮,调用AddEditRecipesActivity.java,我在数据表中插入数据。但是当我按下这个按钮时,我的应用程序崩溃了。
这是 LogCat 消息。
08-20 04:13:20.315: E/Your TAG,(9425): Your Message
- 08-20 04:13:20.315: E/Your TAG,(9425): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.behealthy/com.example.behealthy.AddEditRecipesActivity}: java.lang.NullPointerException
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread.access$600(ActivityThread.java:140)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.os.Handler.dispatchMessage(Handler.java:99)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.os.Looper.loop(Looper.java:137)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread.main(ActivityThread.java:4898)
- 08-20 04:13:20.315: E/Your TAG,(9425): at java.lang.reflect.Method.invokeNative(Native Method)
- 08-20 04:13:20.315: E/Your TAG,(9425): at java.lang.reflect.Method.invoke(Method.java:511)
- 08-20 04:13:20.315: E/Your TAG,(9425): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
- 08-20 04:13:20.315: E/Your TAG,(9425): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
- 08-20 04:13:20.315: E/Your TAG,(9425): at dalvik.system.NativeStart.main(Native Method)
- 08-20 04:13:20.315: E/Your TAG,(9425): Caused by: java.lang.NullPointerException
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:228)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
- 08-20 04:13:20.315: E/Your TAG,(9425): at com.example.behealthy.AddEditRecipesActivity.<init>(AddEditRecipesActivity.java:27)
- 08-20 04:13:20.315: E/Your TAG,(9425): at java.lang.Class.newInstanceImpl(Native Method)
- 08-20 04:13:20.315: E/Your TAG,(9425): at java.lang.Class.newInstance(Class.java:1319)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
- 08-20 04:13:20.315: E/Your TAG,(9425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
- 08-20 04:13:20.315: E/Your TAG,(9425): ... 11 more
谢谢。