Android NetworkOnMainThreadException
Because you are performing n/w operations
on main Ui thread
Either Use AsyncTask
or Thread
AsyncTask: Docs
class myAsync extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
// Keep in mind You Can't Update UI Part here
JSONObject jObject = (new JSONParser(this))
.getJSONObject("http://192.168.0.81:8080/content/test.json");
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
// Handle/Update UI Part
}
}
Call it like
new myAsync().execute();