java - Nullpointer exception on Hashmap for CustomListAdapter? -
i cant life of me figure out. want add custom data listview hashmap .
the process put info in hashmap, put hashmap arraylist - causes nullpointerexception, , dont know how fix this.
public class recipedownload extends activity { // declare variables arraylist<hashmap<string, string>> fooditems; public static string titleoffood = "titleoffood"; public static string linktorecipe = "linktorecipe"; public static string ingredientsofrecipe = "ingredientsofrecipe"; public static string thumbnailoffood = "thumbnail"; public hashmap<string, string> recipeitems = new hashmap<string, string>(); edittext searchfield; button researchbutton; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // view listview_main.xml setcontentview(r.layout.recipedownload); // declaration of button "refreshbutton". researchbutton = (button) findviewbyid(r.id.refreshbutton); // declaration of edittext "searchfield" searchfield = (edittext) findviewbyid(r.id.searchfield); searchfield.setselected(false); searchfield.settext(mainactivity.itemtosearch); // execute connectioncheck checkconnection(); // recipe list context menu //registerforcontextmenu(recipelist); recipeitems.put(titleoffood, "href"); recipeitems.put(linktorecipe, "href"); recipeitems.put(ingredientsofrecipe, "ingredients"); recipeitems.put(thumbnailoffood, "thumbnail"); fooditems.add(recipeitems); } this creates nullpointerexception @ row 71.
09-04 16:16:46.589: e/androidruntime(10372): fatal exception: main 09-04 16:16:46.589: e/androidruntime(10372): java.lang.runtimeexception: unable start activity componentinfo{org.paul.barcoder/org.paul.barcoder.recipedownload}: java.lang.nullpointerexception 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2125) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread.access$600(activitythread.java:140) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread$h.handlemessage(activitythread.java:1227) 09-04 16:16:46.589: e/androidruntime(10372): @ android.os.handler.dispatchmessage(handler.java:99) 09-04 16:16:46.589: e/androidruntime(10372): @ android.os.looper.loop(looper.java:137) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread.main(activitythread.java:4898) 09-04 16:16:46.589: e/androidruntime(10372): @ java.lang.reflect.method.invokenative(native method) 09-04 16:16:46.589: e/androidruntime(10372): @ java.lang.reflect.method.invoke(method.java:511) 09-04 16:16:46.589: e/androidruntime(10372): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) 09-04 16:16:46.589: e/androidruntime(10372): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) 09-04 16:16:46.589: e/androidruntime(10372): @ dalvik.system.nativestart.main(native method) 09-04 16:16:46.589: e/androidruntime(10372): caused by: java.lang.nullpointerexception 09-04 16:16:46.589: e/androidruntime(10372): @ org.paul.barcoder.recipedownload.oncreate(recipedownload.java:71) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activity.performcreate(activity.java:5206) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1083) 09-04 16:16:46.589: e/androidruntime(10372): @ android.app.activitythread.performlaunchactivity(activitythread.java:2064) 09-04 16:16:46.589: e/androidruntime(10372): ... 11 more any appreciated.
initialize fooditems. didn't.
fooditems = new arraylist<hashmap<string, string>>(); btw, start variable names lowercase.
Comments
Post a Comment