Monday, July 25, 2011

[android-developers] Unable to start activity, null pointer exception

I am working in tha sample of notepad3!
I have a list with a simple cursor adapter. When I click in a list
item my app crashes. the logcat:


07-25 16:44:59.403: ERROR/AndroidRuntime(580): FATAL EXCEPTION: main
07-25 16:44:59.403: ERROR/AndroidRuntime(580):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.desktop.newtodo1/com.desktop.newtodo1.Editnote}:
java.lang.NullPointerException
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1622)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
1638)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.os.Looper.loop(Looper.java:123)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread.main(ActivityThread.java:3647)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
java.lang.reflect.Method.invokeNative(Native Method)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
java.lang.reflect.Method.invoke(Method.java:507)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
dalvik.system.NativeStart.main(Native Method)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): Caused by:
java.lang.NullPointerException
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
com.desktop.newtodo1.Editnote.populateFields(Editnote.java:344)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
com.desktop.newtodo1.Editnote.onCreate(Editnote.java:198)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1586)
07-25 16:44:59.403: ERROR/AndroidRuntime(580): ... 11 more

The code where the app crashes is:

private void populateFields() {
if (mRowId != null) {
Log.d("populatefields", "" + mRowId); // this result is
coorect, when I click the second item, the mRowId =2
Cursor note = mDbHelper.fetchNote(mRowId); // this is where
the app crashes

startManagingCursor(note);
....}

thanks in advance!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment