Migrating One Android JSON App Into a simple app in Android Migrating One Android JSON App Into a simple app in Android json json

Migrating One Android JSON App Into a simple app in Android


It is recommended to use AsyncTask for network operations.Prior to Honey Comb it won't give any error but from HoneyComb version network operations on Main UI thread will result in NetworkOnUIthread exception.

So Call your : JSONObject json = jParser.getJSONFromUrl(url); to doInBackGround() method of async task and update your UI with the results in OnPostExecute Method.


From your logcat

11-22 12:10:56.958: E/AndroidRuntime(381): java.lang.RuntimeException: Unable to start activity          ComponentInfo{com.example.assent.app/com.example.assent.app.AndroidJSONParsingActivity}: android.os.NetworkOnMainThreadException

You are downloading your json on the main thread, wich throws and exception on Android 3.0+.

The specific line is this : JSONObject json = jParser.getJSONFromUrl(url);. Move it to another thread and it should fix your problem.

Consider using an AsyncTask, or check other options here