android - Using IMEI as a parameter for JSON Service -
after grasping asynctask, have run yet road bump. using json (which connects local sqlserver, retrieve object using imei string parameter. have set breakpoint asynctask call , crashes, without walking through. imei of each mobile stored in database.
i implementing following asynctask hope of running on device, , not on emulator.
i suspect may have device, both web services running on pc. have changed proxy , port in apn settings coincide uri of service still doesn't respond.
telephonymanager telephonymanager = (telephonymanager) this.getsystemservice(context.telephony_service); imei = telephonymanager.getdeviceid(); new loaddevice().execute(imei);
this code snippet oncreate method.
here asynctask class:
//asynctask load manifestid device public class loaddevice extends asynctask<string, string, manifests> { private progressdialog progressdialog = new progressdialog(mainactivity.this); inputstream inputstream = null; string thestring = ""; stringbuilder builder; protected void onpreexecute() { progressdialog.setmessage("getting assigned manifest..."); progressdialog.show(); progressdialog.setoncancellistener(new oncancellistener() { public void oncancel(dialoginterface arg0) { loaddevice.this.cancel(true); } }); } @override protected manifests doinbackground(string... arg0) { try { //http request httpget request = new httpget(centraluri + "/loaddevice/" + imei); //set hedear data in json format request.setheader("accept", "application/json"); request.setheader("content-type", "application/json"); defaulthttpclient client = new defaulthttpclient(); //get response httpresponse response = client.execute(request); httpentity entity = response.getentity(); //read content inputstream = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(is)); builder = new stringbuilder(); string line; while ((line = reader.readline()) != null) { builder.append(line); } is.close(); thestring = builder.tostring(); jsonobject manifestjson = new jsonobject(thestring); jsonarray manifest = manifestjson.getjsonarray("loaddeviceresult"); for(int = 1; < manifest.length(); i++) { jsonobject manobj = manifest.getjsonobject(i); man.manifestid = manobj.getint("originalsogmanifestid"); man.devicemanifestid = manobj.getint("devicemanifestid"); man.imei = manobj.getstring("imei"); man.jobtype = manobj.getstring("prefix"); man.regno = manobj.getstring("regno"); man.complete = manobj.getboolean("complete"); man.datecomplete = manobj.getstring("datecomplete"); } } catch (exception e) { e.printstacktrace(); } return man; } protected void onpostexecute(manifests manifest) { //manifests manifesttoget = new manifests(); //string manifestcode = manifesttoget.getjobtype() + integer.tostring(manifesttoget.getmanifestid()); //new getmanifestitems().execute(manifestcode); } }
my other asynctasks working fine. however, after put beast in first asynctask run, others not getting hit.
here asynctask relies on property in object retrieved first asynctask:-
//asynctask manifestitem each manifest public class getmanifestitems extends asynctask<string, string, arraylist<manifestitemobj>> { private progressdialog progressdialog = new progressdialog(mainactivity.this); inputstream inputstream = null; string thestring = ""; stringbuilder builder; protected void onpreexecute() { progressdialog.setmessage("loading manifests..."); progressdialog.show(); progressdialog.setoncancellistener(new oncancellistener() { public void oncancel(dialoginterface arg0) { getmanifestitems.this.cancel(true); } }); } @override protected arraylist<manifestitemobj> doinbackground(string... params) { manifests assign = man; string manifestcode = assign.getjobtype() + integer.tostring(assign.getmanifestid()); try { //http request httpget request = new httpget(pod_uri + "/getjobs/" + manifestcode); //set hedear data in json format request.setheader("accept", "application/json"); request.setheader("content-type", "application/json"); defaulthttpclient client = new defaulthttpclient(); //get response httpresponse response = client.execute(request); httpentity entity = response.getentity(); //read content inputstream = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(is)); builder = new stringbuilder(); string line; while ((line = reader.readline()) != null) { builder.append(line); } is.close(); thestring = builder.tostring(); jsonobject jobsjson = new jsonobject(thestring); jsonarray jobs = jobsjson.getjsonarray("getjobsresult"); manifestitemobj midumb = new manifestitemobj(); midumb.manifestitemid = -1; midumb.fkid = -1; midumb.jobtype = "--please select--"; for(int = 1; < jobs.length(); i++) { jsonobject mit = jobs.getjsonobject(i); manifestitemobj mi = new manifestitemobj(); mi.manifestitemid = mit.getint("manifestitemid"); mi.jobtype = mit.getstring("jobtype"); mi.fkid = mit.getint("fkid"); //shipto object jsonobject stobj = mit.getjsonobject("shipto"); shipto sto = new shipto(); sto.shiptoid = stobj.getint("shiptoid"); sto.shiptoname = stobj.getstring("shiptoname"); sto.shiptoaddress1 = stobj.getstring("shiptoaddress1"); sto.shiptoaddress2 = stobj.getstring("shiptoaddress2"); sto.shiptocity = stobj.getstring("shiptocity"); sto.shiptopostcode = stobj.getstring("shiptopcode"); sto.shiptostate = stobj.getstring("shiptostate"); mi.shipto = sto; joblist.add(mi); } joblist.add(0, midumb); } catch (exception e) { e.printstacktrace(); } return joblist; } protected void onpostexecute(arraylist<manifestitemobj> mio) { manifestitemadapter mia = new manifestitemadapter(mainactivity.this, android.r.layout.simple_spinner_item, joblist); this.progressdialog.dismiss(); list_job.setadapter(mia); } }
edit: here logcat. i'm suspecting button being cast spinner. not intention that's it's saying:-
05-03 14:20:20.603: e/trace(797): error opening trace file: no such file or directory (2) 05-03 14:20:21.204: d/androidruntime(797): shutting down vm 05-03 14:20:21.204: w/dalvikvm(797): threadid=1: thread exiting uncaught exception (group=0x40a13300) 05-03 14:20:21.224: e/androidruntime(797): fatal exception: main 05-03 14:20:21.224: e/androidruntime(797): java.lang.runtimeexception: unable start activity componentinfo{com.signonglass/com.signonglass.mainactivity}: java.lang.classcastexception: android.widget.button cannot cast android.widget.spinner 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread.access$600(activitythread.java:130) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 05-03 14:20:21.224: e/androidruntime(797): @ android.os.handler.dispatchmessage(handler.java:99) 05-03 14:20:21.224: e/androidruntime(797): @ android.os.looper.loop(looper.java:137) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread.main(activitythread.java:4745) 05-03 14:20:21.224: e/androidruntime(797): @ java.lang.reflect.method.invokenative(native method) 05-03 14:20:21.224: e/androidruntime(797): @ java.lang.reflect.method.invoke(method.java:511) 05-03 14:20:21.224: e/androidruntime(797): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 05-03 14:20:21.224: e/androidruntime(797): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 05-03 14:20:21.224: e/androidruntime(797): @ dalvik.system.nativestart.main(native method) 05-03 14:20:21.224: e/androidruntime(797): caused by: java.lang.classcastexception: android.widget.button cannot cast android.widget.spinner 05-03 14:20:21.224: e/androidruntime(797): @ com.signonglass.mainactivity.oncreate(mainactivity.java:55) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activity.performcreate(activity.java:5008) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 05-03 14:20:21.224: e/androidruntime(797): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 05-03 14:20:21.224: e/androidruntime(797): ... 11 more
could 1 of these 2 things:
- add permission manifest < uses-permission android:name="android.permission.read_phone_state"> (remove space after '<')
- you declaring button in layout file of mainactivity cast spinner while initiating button or vice-versa.
Comments
Post a Comment