我试图从AddEditRecipesActivity.java上启动RecipesActivity.java。在RecipesActivity中,有来自datatable的数据列表。通过按RecipesActivity中的Add按钮,将调用AddEditRecipesActivity.java,在datatable中插入数据。但是当我按下这个按钮时,我的应用程序就崩溃了。
这是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谢谢。
发布于 2013-08-19 23:28:55
从这条线
Caused by: java.lang.NullPointerException我们知道问题在于某些东西是null。从这一行(后面的第一行引用您的项目)
at com.example.behealthy.AddEditRecipesActivity.<init>(AddEditRecipesActivity.java:27)我们知道“空的东西”在AddEditRecipesActivity的第27行
看看那里的null可能是什么,并弄清楚为什么会是null。如果您需要更多的帮助,那么请张贴相关代码。
发布于 2013-08-19 23:28:16
您在第27行的AddEditRecipesActivity中访问的一个变量是null。
如果双击logcat中的消息,eclipse将带您到相关的行。
如果您看不到哪个变量是null,请尝试用
Log.d("MyTag", "The value of xyz="+xyz);或者在调试器下运行代码。
https://stackoverflow.com/questions/18324638
复制相似问题