listview - list view makes android app crash -
i working on health related android app. in this, using floating action button in indexpage.java switch activity foodentry.java(having listview food items). in whenever click on floating button app crashes. 1 thing found out app crashing due listview. please me find solution of it.
this indexpage.java
public class indexpage extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_index_page); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent in = new intent(indexpage.this, foodentry.class); startactivity(in); } }); } }
foodentry.java
public class foodentry extends appcompatactivity { // array of strings... string[] food = {"naan","pav bhaji","chole tikiya", "rice", "soyabean", "milk", "curd", "abc", "def", "dfadf", "fasdfa", "fsadf", "fdsfa", "fga"}; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); arrayadapter adapter = new arrayadapter<>(this, r.layout.activity_item, food); listview listviewfooditems = (listview)findviewbyid(r.id.listviewfood); listviewfooditems.setadapter(adapter); } }
error on logcat
03-31 15:30:58.555 13732-13732/com.praval.healthfreak w/dalvikvm: threadid=1: calling uncaughtexceptionhandler 03-31 15:30:58.556 13732-13732/com.praval.healthfreak e/androidruntime: fatal exception: main process: com.praval.healthfreak, pid: 13732 java.lang.runtimeexception: unable start activity componentinfo{com.praval.healthfreak/com.praval.healthfreak.foodentry}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2389) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2441) @ android.app.activitythread.access$900(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1354) @ android.os.handler.dispatchmessage(handler.java:110) @ android.os.looper.loop(looper.java:193) @ android.app.activitythread.main(activitythread.java:5345) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:828) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:644) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.praval.healthfreak.foodentry.oncreate(foodentry.java:20) @ android.app.activity.performcreate(activity.java:5343) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1088) @ android.app.activitythread.performlaunchactivity(activitythread.java:2343) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2441) @ android.app.activitythread.access$900(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1354) @ android.os.handler.dispatchmessage(handler.java:110) @ android.os.looper.loop(looper.java:193) @ android.app.activitythread.main(activitythread.java:5345) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:828) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:644) @ dalvik.system.nativestart.main(native method)
you forget add
setcontentview(r.layout.activity_layout);
in foodentry activity
Comments
Post a Comment