http://lmgtfy.com/?q=NetworkOnMainThreadException+in+android
On Thu, Oct 25, 2012 at 4:40 PM, aueddonline <commsult...@gmail.com> wrote: > Below I have some of my MainActivity class which starts by making a http > post request to the web server running on my development laptop. The > webpage outputs some JSON also shown below; However I am getting > a NetworkOnMainThreadException when running the app. I can go into the > browser within the emulator and bring up the php page no problem. I also > have the following permission set in my manifest xml; *<uses-permission > android:name="android.permission.INTERNET"></uses-permission>*. Any Help > out there? > > > [{"city_id":"1","city_name":"Adotol"},{"city_id":"2","city_name":"Aberdeen"}][{"city_id":"1","city_name":"Adotol"},{"city_id":"2","city_name":"Aberdeen"}] > > > > public class MainActivity extends ListActivity { > > > JSONArray jArray; > String result = null; > InputStream is = null; > StringBuilder sb=null; > > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > //setContentView(R.id.list); > > > ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); > //http post > try{ > HttpClient httpclient = new DefaultHttpClient(); > String phpaddress = "*http://10.0.2.2/androidselectservice.php*"; > System.out.println("'"+phpaddress+"'"); > HttpPost httppost = new HttpPost(phpaddress); > httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > HttpResponse response = httpclient.execute(httppost); > HttpEntity entity = response.getEntity(); > is = entity.getContent(); > }catch(Exception e){ > Log.e("log_tag", "Error in http connection "+e.toString()); > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- live and let LIVE!!! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en