java - Object is null set in Defalut add Card in Arraylist -
i create default class see list cart in app
public class default extends application { public arraylist<card> listcard; public arraylist<card> getlistcard() { return listcard; } public void setlistcard(arraylist<card> listcard) { this.listcard = listcard; } }
next when
public class scanqrcodeactivity extends appcompatactivity { private arraylist<card> cardlist;
....
if (hotpvalue.equals(passwordhotp)) { card card = new card(path3, base32, namecard, intervaltotp, passwordhotp, getdate(), expirationdate, hotpvalue); default app = (default) getapplicationcontext(); cardlist = app.getlistcard(); cardlist.add(card); // show error line code app.setlistcard(cardlist); cardlist = new arraylist<card>(); cardlist= app.getlistcard(); system.out.println("dodanokarte"+card.getnamecard()); }
see log
process: com.novum.smrtkarta, pid: 13844 java.lang.nullpointerexception: attempt invoke virtual method 'boolean java.util.arraylist.add(java.lang.object)' on null object reference @ com.xxxx.smrtkarta.activity.scanqrcodeactivity$3$1.run(scanqrcodeactivity.java:277) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
what wrong ?
this should work have change change:
arraylist<card> listcard
to:
arraylist<card> list = new arraylist<card>;
Comments
Post a Comment