java - Can't access ArrayList in other view? android null pointer exception -


i trying access arraylist of integers previous class set in previous view doesn't seem saving arraylist correctly when go new view think deletes whatever there?

is there anyway access "lightinfo" set?

connecttest declaration

public class connecttest extends mainactivity {     textview out;     private static final int request_enable_bt = 1;     private bluetoothadapter btadapter = null;     private bluetoothsocket btsocket = null;     private outputstream outstream = null;      // known spp uuid     private static final uuid my_uuid =             uuid.fromstring("00001101-0000-1000-8000-00805f9b34fb");      // insert server's mac address     private static string address = "a4:5e:60:eb:3c:e8";     arraylist<integer> temp = ((mainactivity) getapplicationcontext()).lightinfo; 

call temp creates error:

 string finalmessage = "";         (int = 0; < temp.size(); i++) {             finalmessage = finalmessage + temp.get(i) + "\n";         }          string message = finalmessage; 

mainactivity declaration

public class mainactivity extends appcompatactivity {       private final static int request_enable_bt = 1;     uuid myuuid = uuid.randomuuid();     private static final int discover_duration = 300;     private static final int request_blu = 1;     arrayadapter<string> marrayadapter;     arraylist<double> currentbodytemp;     bluetoothadapter mbluetoothadapter = bluetoothadapter.getdefaultadapter();     boolean targettimezoneisahead = false;     boolean targettimezoneisbehind = false;      int currentwaketime = 420;     int currentsleeptime = 1320;      int targetwaketime = 0;     int targetsleeptime = 0;     int daysleft = 0;     int timedifference = 0;      public arraylist<integer> lightinfo; 

error message:

10-27 12:59:56.141 15803-15803/com.teamfara.circadianrhythmmonitor4 d/androidruntime: shutting down vm 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime: fatal exception: main 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime: process: com.teamfara.circadianrhythmmonitor4, pid: 15803 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime: java.lang.runtimeexception: unable instantiate activity componentinfo{com.teamfara.circadianrhythmmonitor4/com.teamfara.circadianrhythmmonitor4.connecttest}: java.lang.nullpointerexception: attempt invoke virtual method 'android.content.context android.content.context.getapplicationcontext()' on null object reference 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.performlaunchactivity(activitythread.java:2964) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.handlelaunchactivity(activitythread.java:3218) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.access$1000(activitythread.java:198) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread$h.handlemessage(activitythread.java:1676) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.os.handler.dispatchmessage(handler.java:102) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.os.looper.loop(looper.java:145) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.main(activitythread.java:6837) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.reflect.method.invoke(native method) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.reflect.method.invoke(method.java:372) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1404) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1199) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:  caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.content.context android.content.context.getapplicationcontext()' on null object reference 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.content.contextwrapper.getapplicationcontext(contextwrapper.java:111) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ com.teamfara.circadianrhythmmonitor4.connecttest.<init>(connecttest.java:34) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.reflect.constructor.newinstance(native method) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.class.newinstance(class.java:1684) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.instrumentation.newactivity(instrumentation.java:1080) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.performlaunchactivity(activitythread.java:2954) 10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.handlelaunchactivity(activitythread.java:3218)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.access$1000(activitythread.java:198)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread$h.handlemessage(activitythread.java:1676)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.os.handler.dispatchmessage(handler.java:102)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.os.looper.loop(looper.java:145)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ android.app.activitythread.main(activitythread.java:6837)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.reflect.method.invoke(native method)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ java.lang.reflect.method.invoke(method.java:372)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1404)  10-27 12:59:56.151 15803-15803/com.teamfara.circadianrhythmmonitor4 e/androidruntime:     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1199)  

thank you!

you can not typecast object , expect work. please use proper data passing mechanisms. try this:

passing data through intent , receiving it


Comments


  1. Wow! Great post; I liked how you explained that the difference between full-time angular js developer salary is almost similar to freelance angular js developers' pay. I also wanted to join the freelancing platform for my development work, and I came across Eiliana.com; it is a new and great platform for technical experts.

    ReplyDelete
  2. Well explained. WordPress PHP framework also provides you with all the features you need to build an eCommerce website. However, if you are a professional freelancer and looking for some top PHP freelancing projects then sign up today with Eiliana.com a global freelancing portal.

    ReplyDelete

Post a Comment

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -