Android failing to change view -


so pretty new android , having issue changing views. have simple task list application , want able open "details" view when clicked. here's have:

public class viewtask extends activity {     protected taskerdbhelper db;     private list<task> list;     private myadapter adapt;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.view_task);         //db variable of type taskerdbhelper         db = new taskerdbhelper(this);         list = db.getalltasks();         adapt = new myadapter(this, r.layout.list_inner_view , list);         listview listtask = (listview)findviewbyid(r.id.listview1);          listtask.setadapter(adapt);         listtask.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {                 string taskname = (string)((viewholder)view.gettag()).taskname.gettext();                 toast.maketext(getapplicationcontext(), "clicked: " + taskname, toast.length_long).show();                 intent myintent = new intent(getapplicationcontext(), details.class);                 myintent.putextra("task_name", taskname);                 startactivity(myintent);             }         });     } .... } 

when click task, error:

07-11 00:54:58.671    1918-1918/com.example.tasker             e/androidruntime: fatal exception: main         java.lang.runtimeexception: unable start activity componentinfo{com.example.tasker/com.example.tasker.details}: java.lang.nullpointerexception         @ android.app.activitythread.performlaunchactivity(activitythread.java:2180)         @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230)         @ android.app.activitythread.access$600(activitythread.java:141)         @ android.app.activitythread$h.handlemessage(activitythread.java:1234)         @ android.os.handler.dispatchmessage(handler.java:99)         @ android.os.looper.loop(looper.java:137)         @ android.app.activitythread.main(activitythread.java:5041)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:511)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)         @ dalvik.system.nativestart.main(native method)         caused by: java.lang.nullpointerexception         @ com.example.tasker.details.oncreate(details.java:17)         @ android.app.activity.performcreate(activity.java:5104)         @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080)         @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 

what doing wrong?

try string taskname = (string) adapter.getitem(i) instead of view.gettag line. how retrieve row's content.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -