I try to load Json from URL. By not using AsyncTask class on previous version, It worked well.
However call getJSONFromUrl(currentURL) directly from main Thread (someone told me) is not accepted in 3.2 or higher Android versons.
So, I tried by the following code.
this is my code:
private static String urlTruyenMoiNhat = "myUrl";
private static String currentURL = urlTruyenMoiNhat;
private static JSONObject jSonGetFromCurrentURL = null;
//some stuff....
currentURL = urlTruyenMoiNhat;
GetJsonAsync getJson = new GetJsonAsync();
getJson.execute();
RetreiveListStory(jSonGetFromCurrentURL);
This is my GetJsonAsync class:
private class GetJsonAsync extends AsyncTask <String, Void, String> {
@Override
protected void onPreExecute() {
// Do stuff before the operation
}
protected String doInBackground(String... params){
JSONParser jParser = new JSONParser();
jSonGetFromCurrentURL = jParser.getJSONFromUrl(currentURL);
return null;
}
@Override
protected void onPostExecute(String result) {
// Do stuff after the operation
}
}
I don't know why it through exception:
11-28 13:30:44.084: E/AndroidRuntime(828): FATAL EXCEPTION: main
11-28 13:30:44.084: E/AndroidRuntime(828): java.lang.RuntimeException: Unable to start activity ComponentInfo{vn.truyencuoihay/vn.truyencuoihay.MainActivity}: java.lang.NullPointerException
Please help me overcome this problem.
Thanks!