I'm newbye in android world and I'm trying to retrieve a JSONArray from this URL: http://www.softmarketing.it/json/view/azienda/7
TabHostExample.java:
public class TabHostExample extends TabActivity {
private static String url = "http://www.softmarketing.it/json/view/azienda/7";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_host_example);
//JSONParser parser= new JSONParser();
//JSONObject myJSON= parser.makeHttpRequest(url, "POST", null);
try{
// Create a new HTTP Client
DefaultHttpClient defaultClient = new DefaultHttpClient();
// Setup the get request
HttpGet httpGetRequest = new HttpGet("http://www.softmarketing.it/json/view/azienda/7");
// Execute the request in the client
HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
// Grab the response
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Instantiate a JSON object from the request response
JSONObject jsonObject = new JSONObject(json);
} catch(Exception e){
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
.....
In the LogCat I see this:
12-16 08:14:41.987: E/MYAPP(1183): exception: null
12-16 08:21:34.927: E/MYAPP(1245): exception: null
and the variable e has these values:
e: cause: NetworkOnMainThreadEception
and others values...
Could you help me please? It's been three days that I'm trying to solve the parsing...Thanks