i am getting fatal exception:main in android and the application is not getting executed on emulator? -
`
public class jsonexampleactivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_json_example); httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://codeincloud.tk/json_android_example.php"); textview textview = (textview)findviewbyid(r.id.textview1); try { httpresponse response = httpclient.execute(httppost); string jsonresult = inputstreamtostring(response.getentity().getcontent()).tostring(); jsonobject object = new jsonobject(jsonresult); string name = object.getstring("name"); string verion = object.getstring("version"); textview.settext(name + " - " + verion); } catch (jsonexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } private stringbuilder inputstreamtostring(inputstream is) { string rline = ""; stringbuilder answer = new stringbuilder(); bufferedreader rd = new bufferedreader(new inputstreamreader(is)); try { while ((rline = rd.readline()) != null) answer.append(rline); } } catch (ioexception e) { e.printstacktrace(); } return answer; } }`
the base of exception appears coming "fileoutputstream.write", have added write permissions manifest?
<uses-permission android:name="android.permission.write_external_storage"/>
Comments
Post a Comment