android - New to java - Attempt to invoke virtual method 'void -
i new coding , java , got problem , wasn't able fix it. strange thing error happens on android 5.
below error message
java.lang.nullpointerexception: attempt invoke virtual method 'void com.nostra13.universalimageloader.core.imageloader.displayimage(java.lang.string, android.widget.imageview, com.nostra13.universalimageloader.core.displayimageoptions)' on null object reference @ com.fragments.activity.storeactivity$1.onmgarrayadaptercreated(storeactivity.java:143) @ com.adapters.mgarrayadapter.getview(mgarrayadapter.java:82)
storeactivity.java
public void onmgarrayadaptercreated (mgarrayadapter adapter, view v, int position, viewgroup viewgroup, object obj){ // todo auto-generated method stub final store store = arraydata.get(position); photo p = q.getphotobystoreid(store.getstore_id()); mgimageview imgviewphoto = (mgimageview) v.findviewbyid(r.id.imgviewphoto); imgviewphoto.setcornerradius(0.0f); imgviewphoto.setborderwidth(uiconfig.border_width); imgviewphoto.setbordercolor(getresources().getcolor(uiconfig.theme_black_color)); imgviewphoto.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub intent = new intent(storeactivity.this, detailactivity.class); i.putextra("store", store); storeactivity.this.startactivity(i); } }); if (p != null) { mainactivity.getimageloader().displayimage(p.getphoto_url(), imgviewphoto, options); } else { imgviewphoto.setimageresource(uiconfig.slider_placeholder); } }
mgarrayadapter.java
public class mgarrayadapter extends baseadapter { private context c; private int resid; private onmgarrayadapterlistener mcallback; public list<object> objects; public interface onmgarrayadapterlistener { public void onmgarrayadaptercreated(mgarrayadapter adapter, view v, int position, viewgroup viewgroup, object obj); } public void setonmgarrayadapterlistener(onmgarrayadapterlistener listener) { try { mcallback = (onmgarrayadapterlistener) listener; } catch (classcastexception e) { throw new classcastexception(this.tostring() + " must implement onmgarrayadapterlistener"); } } public mgarrayadapter(context c, arraylist<object> objects, int resid) { this.c = c; this.objects = objects; this.resid = resid; } @override public int getcount() { // todo auto-generated method stub return objects.size(); } @override public object getitem(int pos) { // todo auto-generated method stub return objects.get(pos); } @override public long getitemid(int pos) { // todo auto-generated method stub return pos; } @override public view getview(int pos, view v, viewgroup viewgroup) { // todo auto-generated method stub viewholder viewholder = null; if (v == null) { layoutinflater li = (layoutinflater) c.getsystemservice(context.layout_inflater_service); v = li.inflate(resid, null); viewholder = new viewholder(); viewholder.view = v; v.settag(viewholder); } else { viewholder = (viewholder) v.gettag(); log.w("mglistadapter class", "view being reused."); } if (mcallback != null) mcallback.onmgarrayadaptercreated(this, viewholder.view, pos, viewgroup, objects.get(pos)); return v; } public class viewholder { public view view; } public void add(object obj) { if (objects == null) objects = new arraylist<object>(); objects.add(obj); } public void clearall() { if (objects == null) objects = new arraylist<object>(); objects.clear(); } }
why not try:
public void add(object obj) { if(objects == null) objects = new arraylist<object>(); objects.add(obj); } public void clearall(object obj) { if(objects == null) objects = new arraylist<object>(); objects.clear(); }
Comments
Post a Comment