android - My activity is unable to connect to website and display JSON data using volley -
i have been trying use volley connect , parse json data in activity posted below each time application forces close. value of urljsonobj correct since displays data when call browser. doing wrong?
package gsie.bizlink; import android.content.intent; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.gridview; import android.widget.listview; import android.widget.textview; import android.widget.toast; import com.android.volley.defaultretrypolicy; import com.android.volley.request; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.volleylog; import com.android.volley.toolbox.jsonobjectrequest; import com.android.volley.toolbox.stringrequest; import com.android.volley.toolbox.volley; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.util.arraylist; import com.loopj.android.http.asynchttpclient; import com.loopj.android.http.jsonhttpresponsehandler; import android.app.progressdialog; import android.os.asynctask; public class cinteretsactivity extends actionbaractivity implements view.onclicklistener { private string prenom; private string nom; private string telephone1; private string telephone2; private string telephone3; private string email; private textview myentries; private static final string urljsonobj ="http://www.pmsgroom.net/bizlink/cinteretsservlet"; private arraylist<cinteret> cinteretslist=new arraylist<cinteret>(); private cinteretsadapter cinteretsadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_cinterets); //myentries=(textview) findviewbyid(r.id.textview); intent in=getintent(); prenom=in.getstringextra("prenom"); nom=in.getstringextra("nom"); telephone1=in.getstringextra("telephone1"); telephone2=in.getstringextra("telephone2"); telephone3=in.getstringextra("telephone3"); email=in.getstringextra("email"); //myentries.settext(prenom+"\n"+nom+"\n"+telephone1+"\n"+telephone2+"\n"+telephone3+"\n"+email); //new jsonparse().execute(); //cinteretslist=getlist(); /* asynchttpclient client = new asynchttpclient(); client.get(urljsonobj, new jsonhttpresponsehandler() { @override public void onsuccess(jsonobject jsonobject) { try { jsonarray jarray = jsonobject.getjsonarray("cinterets"); string cinteretiden = ""; string cinterettext = ""; (int = 0; < jarray.length(); i++) { jsonobject cinteret = jarray.getjsonobject(i); cinteretiden = cinteret.getstring("cinteretid"); cinterettext = cinteret.getstring("cinterettxt"); cinteret cint = new cinteret(); cint.setid(cinteretiden); cint.settext(cinterettext); cinteretslist.add(cint); } } catch (jsonexception e) { log.d("jsonerror", "error: " + e); toast.maketext(getapplicationcontext(), "error: " + e.getmessage(), toast.length_long).show(); } } @override public void onfailure(int statuscode, throwable throwable, jsonobject error) { toast.maketext(getapplicationcontext(), "error: " + statuscode + " " + throwable.getmessage(), toast.length_long).show(); log.e("bizlink android", statuscode + " " + throwable.tostring()); } }); */ //volley commence ici jsonobjectrequest jsonobjreq = new jsonobjectrequest(request.method.get, urljsonobj, null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d("reponse", response.tostring()); try { jsonarray jarray=response.getjsonarray("cinterets"); string cinteretiden=""; string cinterettext=""; for(int i=0;i<jarray.length();i++){ jsonobject cinteret=jarray.getjsonobject(i); cinteretiden = cinteret.getstring("cinteretid"); cinterettext=cinteret.getstring("cinterettxt"); cinteret cint=new cinteret(); cint.setid(cinteretiden); cint.settext(cinterettext); cinteretslist.add(cint); } } catch (jsonexception e) { log.d("jsonerror", "error: " + e); toast.maketext(getapplicationcontext(), "error: " + e.getmessage(), toast.length_long).show(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d("mainactivity", "error: " + error); toast.maketext(getapplicationcontext(), error.getmessage(), toast.length_short).show(); } }); jsonobjreq.setretrypolicy(new defaultretrypolicy(5000,5,1f)); appcontroller.getinstance().addtorequestqueue(jsonobjreq); //volley prend fin ici /* if(cinteretslist==null || cinteretslist.isempty()) { toast.maketext(getapplicationcontext(), "liste centres d'interet est vide!", toast.length_long).show(); log.d("reponse", "dedans"); cinteret ct=new cinteret(); ct.setid("1"); ct.settext("immobilier"); cinteretslist.add(ct); cinteret ct2=new cinteret(); ct2.setid("2"); ct2.settext("locations"); cinteretslist.add(ct2); } */ listview listview = (listview) findviewbyid(r.id.listview); cinteretsadapter = new cinteretsadapter(this, cinteretslist); listview.setadapter(cinteretsadapter); button valid=(button) findviewbyid(r.id.finirbtn); valid.setonclicklistener(this); } /*public arraylist<cinteret> getlist(){ final arraylist<cinteret> ci=new arraylist<cinteret>(); requestqueue queue = volley.newrequestqueue(this); jsonobjectrequest jsonobjreq = new jsonobjectrequest(request.method.get, urljsonobj, null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d("reponse", response.tostring()); try { jsonarray jarray=response.getjsonarray("cinterets"); string cinteretiden=""; string cinterettext=""; for(int i=0;i<jarray.length();i++){ jsonobject cinteret=jarray.getjsonobject(i); cinteretiden = cinteret.getstring("cinteretid"); cinterettext=cinteret.getstring("cinterettxt"); cinteret cint=new cinteret(); cint.setid(cinteretiden); cint.settext(cinterettext); ci.add(cint); } } catch (jsonexception e) { log.d("jsonerror", "error: " + e); toast.maketext(getapplicationcontext(), "error: " + e.tostring(), toast.length_long).show(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d("mainactivity", "error: " + error); toast.maketext(getapplicationcontext(), error.tostring(), toast.length_short).show(); } }); //appcontroller.getinstance().addtorequestqueue(jsonobjreq); jsonobjreq.setretrypolicy(new defaultretrypolicy(50000, defaultretrypolicy.default_max_retries, defaultretrypolicy.default_backoff_mult)); queue.add(jsonobjreq); if(ci.size()==0 || ci==null){ log.d("reponse", "dedans"); cinteret ct=new cinteret(); ct.setid("1"); ct.settext("immobilier"); ci.add(ct); cinteret ct2=new cinteret(); ct2.setid("2"); ct2.settext("locations"); ci.add(ct2); } return ci; }*/ @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_cinterets, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } @override public void onclick(view v) { arraylist<string> cinterettextlist=cinteretsadapter.getselectedstring(); arraylist<string> cinteretidlist=cinteretsadapter.getselectedid(); string cinterettextstr=""; (int i=0;i<cinterettextlist.size();i++){ cinterettextstr=cinterettextstr+cinterettextlist.get(i)+"\n"; } intent in=new intent(this,confirminscriptionactivity.class); in.putextra("prenom",prenom); in.putextra("nom", nom); in.putextra("telephone1", telephone1); in.putextra("telephone2",telephone2); in.putextra("telephone3",telephone3); in.putextra("email",email); in.putextra("cinterets",cinterettextstr); startactivity(in); } /*/debut paste private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(cinteretsactivity.this); pdialog.setmessage("chargement ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { jsonparser jparser = new jsonparser(); jsonobject json = jparser.getjsonfromurl(urljsonobj); return json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); try { jsonarray jarray=json.getjsonarray("cinterets"); string cinteretiden=""; string cinterettext=""; for(int i=0;i<jarray.length();i++){ jsonobject cinteret=jarray.getjsonobject(i); cinteretiden = cinteret.getstring("cinteretid"); cinterettext=cinteret.getstring("cinterettxt"); cinteret cint=new cinteret(); cint.setid(cinteretiden); cint.settext(cinterettext); cinteretslist.add(cint); } } catch (jsonexception e) { log.d("jsonerror", "error: " + e); toast.maketext(getapplicationcontext(), "error: " + e.getmessage(), toast.length_long).show(); } } } end paste*/ }
my appcontroller.java is:
public class appcontroller extends application { public static final string tag = appcontroller.class.getsimplename(); private requestqueue mrequestqueue; private static appcontroller minstance; @override public void oncreate() { super.oncreate(); minstance = this; } public static synchronized appcontroller getinstance() { return minstance; } public requestqueue getrequestqueue() { if (mrequestqueue == null) { mrequestqueue = volley.newrequestqueue(getapplicationcontext()); } return mrequestqueue; } public <t> void addtorequestqueue(request<t> req, string tag) { req.settag(textutils.isempty(tag) ? tag : tag); getrequestqueue().add(req); } public <t> void addtorequestqueue(request<t> req) { req.settag(tag); getrequestqueue().add(req); } public void cancelpendingrequests(object tag) { if (mrequestqueue != null) { mrequestqueue.cancelall(tag); } } }
here logcat
06-30 17:03:42.996 20691-20715/gsie.bizlink i/surfacetextureclient﹕ [stc::queuebuffer] (this:0x52f520e8) fps:2.10, dur:1428.35, max:497.07, min:434.57 06-30 17:03:42.997 144-14142/? i/bufferqueue﹕ [gsie.bizlink/gsie.bizlink.contactsactivity](this:0x41b41a80,api:1) [queue] fps:2.10, dur:1428.42, max:497.07, min:434.69 06-30 17:03:43.006 144-234/? i/bufferqueue﹕ [gsie.bizlink/gsie.bizlink.contactsactivity](this:0x41b41a80,api:1) [release] fps:2.10, dur:1428.57, max:496.91, min:434.77 06-30 17:03:43.172 517-1530/? i/activitymanager﹕ start u0 {cmp=gsie.bizlink/.cinteretsactivity (has extras)} pid 20691 06-30 17:03:43.222 517-534/? i/windowmanager﹕ losing focus: window{4212d2d8 u0 gsie.bizlink/gsie.bizlink.contactsactivity} 06-30 17:03:43.329 20691-20691/gsie.bizlink d/abslistview﹕ checkabslistviewllogproperty invalid command 06-30 17:03:43.337 20691-20691/gsie.bizlink d/androidruntime﹕ shutting down vm 06-30 17:03:43.337 20691-20691/gsie.bizlink w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x40d4b9a8) 06-30 17:03:43.344 20691-20691/gsie.bizlink e/androidruntime﹕ fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{gsie.bizlink/gsie.bizlink.cinteretsactivity}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2372) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2424) @ android.app.activitythread.access$600(activitythread.java:162) @ android.app.activitythread$h.handlemessage(activitythread.java:1364) @ android.os.handler.dispatchmessage(handler.java:107) @ android.os.looper.loop(looper.java:194) @ android.app.activitythread.main(activitythread.java:5400) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:837) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:604) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ gsie.bizlink.cinteretsactivity.oncreate(cinteretsactivity.java:149) @ android.app.activity.performcreate(activity.java:5122) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1081) @ android.app.activitythread.performlaunchactivity(activitythread.java:2336) at android.app.activitythread.handlelaunchactivity(activitythread.java:2424) at android.app.activitythread.access$600(activitythread.java:162) at android.app.activitythread$h.handlemessage(activitythread.java:1364) at android.os.handler.dispatchmessage(handler.java:107) at android.os.looper.loop(looper.java:194) at android.app.activitythread.main(activitythread.java:5400) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:525) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:837) at com.android.internal.os.zygoteinit.main(zygoteinit.java:604) at dalvik.system.nativestart.main(native method) 06-30 17:03:43.354 517-783/? w/activitymanager﹕ force finishing activity gsie.bizlink/.cinteretsactivity 06-30 17:03:43.356 517-783/? w/activitymanager﹕ force finishing activity gsie.bizlink/.contactsactivity 06-30 17:03:43.436 517-534/? i/windowmanager﹕ gaining focus: window{42218480 u0 application error: gsie.bizlink} 06-30 17:03:43.459 144-234/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:0) setconsumername: application error: gsie.bizlink 06-30 17:03:43.470 517-21594/? d/aes﹕ process : gsie.bizlink 06-30 17:03:43.470 517-21594/? d/aes﹕ module : gsie.bizlink v1 (1.0) 06-30 17:03:43.471 144-234/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:0) setdefaultbuffersize: w=480, h=190 06-30 17:03:43.475 517-21594/? d/aee/libaee﹕ shell: raise_exp(2, 20691, -1361051648, gsie.bizlink, 0x0x5f14cae0, 0x0x0) 06-30 17:03:43.479 144-12221/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:0) connect: api=2 06-30 17:03:43.479 144-12221/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:2) setsynchronousmode: enabled=1 06-30 17:03:43.479 144-12932/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:2) new graphicbuffer needed 06-30 17:03:43.503 144-234/? i/surfacetexture﹕ [application error: gsie.bizlink](this:0x417f7798,api:2) [void* android::surfacetexture::createimage(egldisplay, const android::sp<android::graphicbuffer>&)] 06-30 17:03:43.856 517-532/? w/activitymanager﹕ activity pause timeout activityrecord{422b2d48 u0 gsie.bizlink/.cinteretsactivity} 06-30 17:03:49.201 144-543/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:2) new graphicbuffer needed 06-30 17:03:49.210 144-22775/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:2) [queue] fps:0.17, dur:5717.39, max:5717.39, min:5717.39 06-30 17:03:49.217 144-234/? i/surfacetexture﹕ [application error: gsie.bizlink](this:0x417f7798,api:2) [void* android::surfacetexture::createimage(egldisplay, const android::sp<android::graphicbuffer>&)] 06-30 17:03:49.217 144-14673/? i/bufferqueue﹕ [application error: gsie.bizlink](this:0x41b25008,api:2) new graphicbuffer needed 06-30 17:03:49.232 144-234/? i/surfacetexture﹕ [application error: gsie.bizlink](this:0x417f7798,api:2) [void* android::surfacetexture::createimage(egldisplay, const android::sp<android::graphicbuffer>&)] 06-30 17:03:53.222 517-532/? w/activitymanager﹕ activity idle timeout activityrecord{422b2d48 u0 gsie.bizlink/.cinteretsactivity} 06-30 17:03:53.859 517-532/? w/activitymanager﹕ activity idle timeout activityrecord{421fd170 u0 gsie.bizlink/.identificationactivity} 06-30 17:04:03.226 517-532/? w/activitymanager﹕ activity destroy timeout activityrecord{42551e40 u0 gsie.bizlink/.contactsactivity} 06-30 17:04:03.229 517-532/? w/activitymanager﹕ activity destroy timeout activityrecord{422b2d48 u0 gsie.bizlink/.cinteretsactivity}
my manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="gsie.bizlink" > <uses-sdk android:targetsdkversion="22" android:minsdkversion="15" /> <uses-permission android:name="android.permission.internet" /> <application android:name=".appcontroller" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".identificationactivity" android:label="@string/title_activity_identification" > </activity> <activity android:name=".contactsactivity" android:label="@string/title_activity_contacts" > </activity> <activity android:name=".cinteretsactivity" android:label="@string/title_activity_cinterets" > </activity> <activity android:name=".confirminscriptionactivity" android:label="@string/title_activity_confirm_inscription" > </activity> </application> </manifest>
as can see code, forgot initialize cinteretslist
. must following code before for
:
arraylist<cinteret> cinteretslist = new arraylist<cinteret>();
Comments
Post a Comment