I’m writing a small android app which will fetch json file content through an URL and then parse and format it.
But the content is not being fetched and my app showing “Unfortunately has stopped”.
Here is my code
Here is the log error
09-12 18:37:15.565: E/AndroidRuntime(2374):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{my.tatasky/my.tatasky.TataskyActivity}:
android.os.NetworkOnMainThreadException09-12 18:37:15.565: E/AndroidRuntime(2374): at
my.tatasky.TataskyActivity.readJson(TataskyActivity.java:154)
In my apps i use gson. It is simple and fast:
https://sites.google.com/site/gson/gson-user-guide
Example:
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
gson.fromJson(json, MyObject[].class);
Try run it on an new thread.