AsyncTask error from getView using a HashMap - Android -
i have set allow me change visibility of textview on online file turned strings , of works fine apart when add in parts of code allows me change visibility of textview. not understand why isn't working. here logcat:
07-21 19:00:46.451 21334-21334/com.example.app e/androidruntime: fatal exception: main java.lang.nullpointerexception @ com.example.app.lazyadapter.getview(lazyadapter.java:68) @ android.widget.abslistview.obtainview(abslistview.java:2035) @ android.widget.listview.measureheightofchildren(listview.java:1244) @ android.widget.listview.onmeasure(listview.java:1155) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1369) @ android.widget.linearlayout.measurevertical(linearlayout.java:660) @ android.widget.linearlayout.onmeasure(linearlayout.java:553) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) @ android.widget.framelayout.onmeasure(framelayout.java:293) @ android.view.view.measure(view.java:12723) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1447) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) @ android.widget.framelayout.onmeasure(framelayout.java:293) @ android.view.view.measure(view.java:12723) @ android.widget.linearlayout.measurevertical(linearlayout.java:812) @ android.widget.linearlayout.onmeasure(linearlayout.java:553) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) @ android.widget.framelayout.onmeasure(framelayout.java:293) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2092) @ android.view.view.measure(view.java:12723) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1064) @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2442) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4575) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:789) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:556) @ dalvik.system.nativestart.main(native method)
here code of adapter error coming from:
public class lazyadapter extends baseadapter { private activity activity; private arraylist<hashmap<string, string>> data; private static layoutinflater inflater=null; public imageloader imageloader; public lazyadapter(activity a, arraylist<hashmap<string, string>> d) { activity = a; data=d; inflater = (layoutinflater)activity.getsystemservice(context.layout_inflater_service); imageloader=new imageloader(activity.getapplicationcontext()); } public int getcount() { return data.size(); } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { view vi=convertview; if(convertview==null) vi = inflater.inflate(r.layout.list_row, null); textview title = (textview)vi.findviewbyid(r.id.title); // title textview date1 = (textview)vi.findviewbyid(r.id.date1); // release date 1 (usually us) textview date2 = (textview)vi.findviewbyid(r.id.date2); // release date 2 (usually europe) textview date3 = (textview)vi.findviewbyid(r.id.date3); // release date 3 (usually australia) textview platforms = (textview)vi.findviewbyid(r.id.platforms); // duration imageview thumb_image=(imageview)vi.findviewbyid(r.id.list_image); // thumb image hashmap<string, string> song = new hashmap<string, string>(); song = data.get(position); //this allows visibility of textviews set via string set online xml map<string, integer> map = new hashmap<string, integer>(); map.put("visible", view.visible); map.put("gone", view.gone); map.put("invisible", view.invisible); // setting values in listview title.settext(song.get(customizedlistview.key_title)); date1.settext(song.get(customizedlistview.key_date1)); date2.settext(song.get(customizedlistview.key_date2)); date3.settext(song.get(customizedlistview.key_date3)); date2.setvisibility(map.get(song.get(customizedlistview.key_date2vis))); //this sets visibility via key_date2vis string using 1 of terms in hashmap above date3.setvisibility(map.get(song.get(customizedlistview.key_date3vis))); platforms.settext(song.get(customizedlistview.key_platforms)); imageloader.displayimage(song.get(customizedlistview.key_thumb_url), thumb_image); return vi; } }
line 68 of lazyadapter.class is:
date2.setvisibility(map.get(song.get(customizedlistview.key_date2vis)));
if me fix problem happy. reading. if need other files don't hesitate ask.
fix: messed string names incredibly stupid error.
at line 68, map
not null, think song
may null after data
(at index position
).
just add logging code debug issue:
hashmap<string, string> song = new hashmap<string, string>(); song = data.get(position); log.i("test", "index is: " + position); log.i("test", "song: " + song);
then turn logcat, may find problem.
if not, comment here output.
update1
the map , song not null. value may null:
map.get(song.get(customizedlistview.key_date2vis));
update2
you can assign default value if null:
int visibility = map.get(song.get(customizedlistview.key_date2vis)); if (null == visibility) visibility = view.visible;
you can add logging find out problem is:
log.i("test", "song :" + song); log.i("test", song.get(customizedlistview.key_date2vis));
Comments
Post a Comment