android - getTag = null pointer -


i keep getting null pointer part of code.

private onclicklistener fbutton = new onclicklistener() {      public void onclick(view v) {          intent myintent = new intent(intent.action_view);          int intid = (integer) v.gettag();          string finalurl = minfo.get(intid).final_url;          myintent.setdata(uri.parse(finalurl));          startactivity(myintent);       } }; 

it auto boxing/unboxing java feature. object casting object accessed retrieve int value, in case, trough integerinstance.intvalue(). if forgot set tag, returned value null, causing npe.

you should check null values.

int intid = (v.gettag() == null) ? -1 : (integer) v.gettag(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -