android - nullpointer exception while starting another activity -
when called activity using intent gives nullpointer exception.
intent
public void showevent(view view){ intent intent = new intent(this, getclicker.class); date = (textview)findviewbyid(r.id.textview2); string datevalue = date.gettext().tostring(); userselection=(textview)findviewbyid(r.id.textview1); string userselectvalue = userselection.gettext().tostring(); intent.putextra(extra_message, datevalue); intent.putextra(extra_message1, userselectvalue); startactivity(intent); }
getclicker.java
package example.events1; import android.app.listactivity; import android.content.intent; import android.database.cursor; import android.os.bundle; import android.support.v4.widget.simplecursoradapter; import android.widget.listview; public class getclicker extends listactivity { classdbopenhelper eventsdata1; cursor cursor1; listview listview ; @override public void oncreate(bundle savedinstancestate) { intent intent = getintent(); string datevalue = intent.getstringextra(firstactivity.extra_message); string userselectvalue = intent.getstringextra(firstactivity.extra_message1); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_second); cursor1 = eventsdata1.getcontact(datevalue,userselectvalue); string[] fromcolumns = {classdbopenhelper.key_event}; int[] toviews = {r.id.event}; simplecursoradapter adapter = new simplecursoradapter(this,r.layout.events, cursor1, fromcolumns, toviews,0 ); listview = getlistview(); listview.setadapter(adapter); } public void ondestroy() { eventsdata1.close(); } }
logcat
08-07 11:52:54.445: e/trace(2926): error opening trace file: no such file or directory (2) 08-07 11:52:58.564: e/androidruntime(2926): fatal exception: main 08-07 11:52:58.564: e/androidruntime(2926): java.lang.runtimeexception: unable start activity componentinfo{example.events1/example.events1.getclicker}: java.lang.nullpointerexception 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread.access$600(activitythread.java:141) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 08-07 11:52:58.564: e/androidruntime(2926): @ android.os.handler.dispatchmessage(handler.java:99) 08-07 11:52:58.564: e/androidruntime(2926): @ android.os.looper.loop(looper.java:137) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread.main(activitythread.java:5041) 08-07 11:52:58.564: e/androidruntime(2926): @ java.lang.reflect.method.invokenative(native method) 08-07 11:52:58.564: e/androidruntime(2926): @ java.lang.reflect.method.invoke(method.java:511) 08-07 11:52:58.564: e/androidruntime(2926): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-07 11:52:58.564: e/androidruntime(2926): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-07 11:52:58.564: e/androidruntime(2926): @ dalvik.system.nativestart.main(native method) 08-07 11:52:58.564: e/androidruntime(2926): caused by: java.lang.nullpointerexception 08-07 11:52:58.564: e/androidruntime(2926): @ example.events1.getclicker.oncreate(getclicker.java:28) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activity.performcreate(activity.java:5104) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 08-07 11:52:58.564: e/androidruntime(2926): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 08-07 11:52:58.564: e/androidruntime(2926): ... 11 more
i don't see you're initializing eventsdata1
, you're using at:
cursor1 = eventsdata1.getcontact(datevalue,userselectvalue);
that can cause null pointer exception.
Comments
Post a Comment