0

RecipesActivity.java から AddEditRecipesActivity.java を起動してみました。RecipesActivity には、datatable からのデータのリストがあります。RecipesActivity で Add ボタンを押すと、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

ありがとう。

4

2 に答える 2

2

この行から

Caused by: java.lang.NullPointerException

問題は、何かが であるということですnull。そして、この行から(その後の最初の行はあなたのプロジェクトを参照しています)

at com.example.behealthy.AddEditRecipesActivity.<init>(AddEditRecipesActivity.java:27)

「null である何か」が 27 行目にあることがわかっています。AddEditRecipesActivity

何がnullそこにあるのかを見て、それがなぜあるのかを理解してくださいnull。さらにヘルプが必要な場合は、関連するコードを投稿してください。

于 2013-08-19T23:28:55.540 に答える
1

AddEditRecipesActivity27 行目でアクセスしている変数はnull.

logcat 内のメッセージをダブルクリックすると、Eclipse は関連する行に移動します。

どの変数が表示されない場合はnull、いくつかの値を出力してみてください

Log.d("MyTag", "The value of xyz="+xyz);

または、デバッガーでコードを実行します。

于 2013-08-19T23:28:16.183 に答える