android - Not able to start new activity on List item click? -
i working on application in not able start new activity on list item click.when click on list item app crashes , not find error. code activity is
public class courieractivity extends activity { dbcontroller dbc=new dbcontroller(this); cursor c; simplecursoradapter sca; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.courierlist); final listview courierlists=(listview) findviewbyid(r.id.courierview); dbc.open(); c=dbc.getcouriername(); string [] ={"couriernames"}; int [] to={r.id.couriertext}; sca=new simplecursoradapter(this, r.layout.courierlistrow, c, from, to); courierlists.setadapter(sca); sca.notifydatasetchanged(); c.requery(); courierlists.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { intent i=new intent(courieractivity.this,serviceactivity.class); i.addflags(intent.flag_activity_clear_top); startactivity(i); } }); } }
and logcat output:
08-24 07:03:54.103: e/androidruntime(1377): fatal exception: main 08-24 07:03:54.103: e/androidruntime(1377): java.lang.runtimeexception: unable start activity componentinfo{com.example.datab/com.example.datab.serviceactivity}: java.lang.nullpointerexception 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread.access$600(activitythread.java:141) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 08-24 07:03:54.103: e/androidruntime(1377): @ android.os.handler.dispatchmessage(handler.java:99) 08-24 07:03:54.103: e/androidruntime(1377): @ android.os.looper.loop(looper.java:137) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread.main(activitythread.java:5041) 08-24 07:03:54.103: e/androidruntime(1377): @ java.lang.reflect.method.invokenative(native method) 08-24 07:03:54.103: e/androidruntime(1377): @ java.lang.reflect.method.invoke(method.java:511) 08-24 07:03:54.103: e/androidruntime(1377): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-24 07:03:54.103: e/androidruntime(1377): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-24 07:03:54.103: e/androidruntime(1377): @ dalvik.system.nativestart.main(native method) 08-24 07:03:54.103: e/androidruntime(1377): caused by: java.lang.nullpointerexception 08-24 07:03:54.103: e/androidruntime(1377): @ com.example.datab.serviceactivity.oncreate(serviceactivity.java:34) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activity.performcreate(activity.java:5104) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 08-24 07:03:54.103: e/androidruntime(1377): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 08-24 07:03:54.103: e/androidruntime(1377): ... 11 more
listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub intent in1 = new intent(getbasecontext(), secondactivity.class); startactivity(in1); } });
also add permission manifest file
<activity android:name=".secondactivity" />
Comments
Post a Comment