java - Null Value for nameArr in ArrayList -
i'm getting null value namearr in following source code , i'm not sure why.
when attempt use following:
system.out.println("testing123"); system.out.println(namearr);
i’m getting:
08-07 19:51:53.540: i/system.out(1048): testing123 08-07 19:51:53.540: i/system.out(1048): []
it appears it’s null @ point – suggestions?
i'm not sure why happening.
source:
public class updateactivity extends activity implements onclicklistener { public static arraylist<string> namearr = new arraylist<string>(); public static arraylist<string> valuearr = new arraylist<string>(); public static arraylist<string> namearr = new arraylist<string>(); public static arraylist<string> apnarr = new arraylist<string>(); public static arraylist<string> mmscarr = new arraylist<string>(); public static arraylist<string> mmsportarr = new arraylist<string>(); public static arraylist<string> mmsproxyarr = new arraylist<string>(); public static arraylist<string> portarr = new arraylist<string>(); public static arraylist<string> proxyarr = new arraylist<string>(); public static int count; alertdialog merroralert = null; public static int totalsteps = 8; private telephonymanager tm; private static final string log_tag = "stdatasettings"; private button mupdatebutton = null; private button massistupdatebutton = null; private button massistinstrbutton = null; private textview mreadagainbutton = null; private int minstructionnumber = 0; alertdialog mconfirmalert = null; public static inputstream stream = null; public static xmlparserhandlerfinal handler; private networktask task; private animationdrawable loadinganimation; private static final string tag = "updateactivity"; context ctx; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); tm = (telephonymanager) getsystemservice(telephony_service); int networktype = tm.getnetworktype(); int phonetype = tm.getphonetype(); task = new networktask(); handler = new xmlparserhandlerfinal(); handler.setcontext(ctx); int version = android.os.build.version.sdk_int; if (phonetype == telephonymanager.phone_type_cdma || (phonetype != telephonymanager.phone_type_gsm && networktype != telephonymanager.network_type_gprs && networktype != telephonymanager.network_type_edge && networktype != telephonymanager.network_type_hsdpa && networktype != telephonymanager.network_type_hspa && networktype != telephonymanager.network_type_hspap && networktype != telephonymanager.network_type_hsupa && networktype != telephonymanager.network_type_umts && networktype != telephonymanager.network_type_lte)) { // if phone type cdma or // phone phone type not gsm , network type none of // network types indicated in statement // display incompatibility message showalert(getstring(r.string.incomp_sm_dialog)); // network type looked because tablets have no phone type. // rely on network type in such cases } else if (!(tm.getsimstate() == telephonymanager.sim_state_absent || (tm.getsimoperator()) .equals(getstring(r.string.numeric_tmo)) || (tm .getsimoperator()).equals(getstring(r.string.numeric_att)))) { // if sim present , not t-mo network sim, // display error message alert indicating use sm sim showalert(getstring(r.string.insert_sm_dialog)); }// no sim or sim t-mo mnc mcc present else if (version < version_codes.ice_cream_sandwich) { // initial ui setup versions lower ics setcontentview(r.layout.update); mupdatebutton = (button) findviewbyid(r.id.update_button); mupdatebutton.setonclicklistener(this); } else {// ics , // task.execute(); if ((tm.getsimoperator()).equals(getstring(r.string.numeric_tmo)) || (tm.getsimoperator()) .equals(getstring(r.string.numeric_att))) { // update apn table in separate thread task.execute(""); // device has t-mo network sim card mcc , mnc correctly // populated // reduce number of steps 6 totalsteps = 6; } // // initial ui setup ics , // setcontentview(r.layout.updating); // string assistupdate = getstring(r.string.apn_app_text_cta2); // charsequence styledtext = html.fromhtml(assistupdate); // xtview assisttext = (textview) // findviewbyid(r.id.apn_app_text_cta2); // sisttext.settext(styledtext); // massistupdatebutton = (button) // findviewbyid(r.id.assist_update_btn); //massistupdatebutton.setonclicklistener(this); } } public void onclick(view v) { if (v == mupdatebutton) { // update button versions lower ics selected // setcontentview(r.layout.updating); onclickmethod(v); intent = new intent(this, configfinalactivity.class); startactivity(i); finish(); } else if (v == massistupdatebutton) { // update button ics , selected // textview in assist update ui textview tv = (textview) findviewbyid(r.id.apn_app_text_cta2); string text = ""; charsequence styledtext = text; switch (minstructionnumber) { case 0: // retrieve instruction string resource corresponding // 2nd set of instructions text = string.format(getstring(r.string.apn_app_text_instr), totalsteps); styledtext = html.fromhtml(text); // update textview correct set of instructions tv.settext(styledtext); // increment instruction number correct instructions // string resource can retrieve next time update // button pressed minstructionnumber++; break; case 1: text = getstring(r.string.apn_app_text_instr2); styledtext = html.fromhtml(text); tv.settext(styledtext); // increment instruction number correct instructions // string resource can retrieve next time update // button pressed minstructionnumber++; break; case 2: // final set of instructions-change corresponding layout setcontentview(r.layout.assist_instructions); string assistupdateinstr = string.format( getstring(r.string.apn_app_text_instr3), totalsteps); styledtext = html.fromhtml(assistupdateinstr); textview assistinstrtext = (textview) findviewbyid(r.id.updated_text); assistinstrtext.settext(styledtext); massistinstrbutton = (button) findviewbyid(r.id.assist_instr_btn); mreadagainbutton = (textview) findviewbyid(r.id.read_again_btn); massistinstrbutton.setonclicklistener(this); mreadagainbutton.setonclicklistener(this); } } else if (v == massistinstrbutton) { // "let's this" button in final instructions screen ics , // selected // create configactivity intent intent = new intent(this, configfinalactivity.class); // invoke configactivity intent start assisted update startactivity(i); finish(); } else if (v == mreadagainbutton) { // go 1st set of instructions if read again selected minstructionnumber = 0; setcontentview(r.layout.assist_update); string assistupdate = getstring(r.string.apn_app_text_cta2); charsequence styledtext = html.fromhtml(assistupdate); textview assisttext = (textview) findviewbyid(r.id.apn_app_text_cta2); assisttext.settext(styledtext); massistupdatebutton = (button) findviewbyid(r.id.assist_update_btn); massistupdatebutton.setonclicklistener(this); } } public void onclickmethod(view v) { mupdatebutton = (button) findviewbyid(r.drawable.btn_update_active_hdpi); } private void showalert(string message) { alertdialog.builder builder = new alertdialog.builder(this); builder.setmessage(message).setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { updateactivity.this.finish(); } }); mconfirmalert = builder.create(); mconfirmalert.show(); } // asynctask call web service private class networktask extends asynctask<string, integer, inputstream> { @override protected void onpreexecute() { super.onpreexecute(); } @override protected inputstream doinbackground(string... params) { try { // saving response in inputstream stream = getqueryresults("https://dl.dropboxusercontent.com/u/31771876/getphonesettings-rsp-eng.xml"); // stream = new bufferedinputstream(https.getinputstream()); datainputstream in = new datainputstream(stream); bufferedreader br = new bufferedreader(new inputstreamreader(in)); string strline; while ((strline = br.readline()) != null) { // print content on console system.out.println (strline); in.close(); } } catch (ioexception e) { log.v(log_tag, e.tostring()); e.printstacktrace(); } catch (saxexception e) { log.v(log_tag, e.tostring()); e.printstacktrace(); } catch (exception e) { log.v(log_tag, e.tostring()); e.printstacktrace(); } // code below plays simple promo animation (int incr = 0; incr < 2; incr++) { // sleep 1/2 second // invoke ui change updating text show 1 dot // , increasing level reduce amount of clipping , // reveals hand image publishprogress(r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block log.d(tag, "sleep failure"); } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block log.d(tag, "sleep failure"); } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block log.d(tag, "sleep failure"); } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block log.d(tag, "sleep failure"); } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full); // sleep 1/2 second try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block log.d(tag, "sleep failure"); } } return stream; } /* * sends query server , gets parsed results in bundle * urlquerystring - url calling webservice */ protected synchronized inputstream getqueryresults(string urlquerystring) throws ioexception, saxexception, sslexception, sockettimeoutexception, exception { // httpsurlconnection https = null; httpsurlconnection https = null; string uri = urlquerystring; url urlo = new url(uri); try { https = (httpsurlconnection) urlo.openconnection(); https.setconnecttimeout(20000); // 20 second timeout https.setrequestproperty("connection", "keep-alive"); if ("gzip".equals(https.getcontentencoding())) { stream = new gzipinputstream(stream); } else stream = https.getinputstream(); } catch (sslexception e) { log.e(log_tag, e.tostring()); e.printstacktrace(); } catch (sockettimeoutexception e) { log.e(log_tag, e.tostring()); e.printstacktrace(); } catch (ioexception e) { log.e(log_tag, e.tostring()); e.printstacktrace(); } catch (exception e) { log.e(log_tag, e.tostring()); e.printstacktrace(); } { // https.disconnect(); } return stream; } @override protected void onprogressupdate(integer... progress) { // call function update image view setprogressimgview(progress[0], progress[1]); } @override protected void onpostexecute(inputstream stream) { super.onpostexecute(stream); // method called parse response , save arraylists success(); } } private void setprogressimgview(integer textviewid, integer imageviewid) { // update image view updating dots // reset view layout in case orientation while updating //setcontentview(r.layout.updating); } @override protected void onrestart() { super.onrestart(); if (merroralert != null) merroralert.dismiss(); } public void success() { // parse response try { handler.getqueryresponse(stream); } catch (saxexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } // set method save arryalists parser setarraylist(); intent = new intent(this, configfinalactivity.class); startactivity(i); finish(); } // method save arraylists parser public static void setarraylist() { //namearr = handler.getnamearr(); namearr.addall(handler.getnamearr()); apnarr = handler.getapnarr(); mmscarr = handler.getmmscarr(); mmsproxyarr = handler.getmmscproxyarr(); mmsportarr = handler.getmmsportarr(); proxyarr = handler.getmmscproxyarr(); portarr = handler.getmmsportarr(); count = handler.getcount(); system.out.println("testing123"); system.out.println(namearr); } }
handler source: (hosted on google docs - exceeds character limit post)
https://docs.google.com/document/d/1rosp9zm0rmfybzvwaxahjelaitwim2ziau_jr9enrzg/edit?usp=sharing
p.s.
i'm getting null pointer error on line:
string value = values.get("name").tostring();
logcat:
08-07 21:30:24.510: e/androidruntime(1998): fatal exception: main 08-07 21:30:24.510: e/androidruntime(1998): java.lang.nullpointerexception 08-07 21:30:24.510: e/androidruntime(1998): @ com.project.new.datasettings.configfinalactivity.shownotification(configfinalactivity.java:509) 08-07 21:30:24.510: e/androidruntime(1998): @ com.project.new.datasettings.configfinalactivity.onclick(configfinalactivity.java:620) 08-07 21:30:24.510: e/androidruntime(1998): @ android.view.view.performclick(view.java:4204) 08-07 21:30:24.510: e/androidruntime(1998): @ android.view.view$performclick.run(view.java:17355) 08-07 21:30:24.510: e/androidruntime(1998): @ android.os.handler.handlecallback(handler.java:725) 08-07 21:30:24.510: e/androidruntime(1998): @ android.os.handler.dispatchmessage(handler.java:92) 08-07 21:30:24.510: e/androidruntime(1998): @ android.os.looper.loop(looper.java:137) 08-07 21:30:24.510: e/androidruntime(1998): @ android.app.activitythread.main(activitythread.java:5041) 08-07 21:30:24.510: e/androidruntime(1998): @ java.lang.reflect.method.invokenative(native method) 08-07 21:30:24.510: e/androidruntime(1998): @ java.lang.reflect.method.invoke(method.java:511) 08-07 21:30:24.510: e/androidruntime(1998): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-07 21:30:24.510: e/androidruntime(1998): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-07 21:30:24.510: e/androidruntime(1998): @ dalvik.system.nativestart.main(native method) 08-07 21:30:28.750: i/process(1998): sending signal. pid: 1998 sig: 9
it appears it’s null @ point – suggestions?
no, it's not null
. empty list (size = 0).
side note: having variable named namearr
, variable named namearr
confusing.
Comments
Post a Comment