0

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.NetworkOnMainThreadException

09-12 18:37:15.565: E/AndroidRuntime(2374): at my.tatasky.TataskyActivity.readJson(TataskyActivity.java:154)

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Bilbo Baggins
  • 3,644
  • 8
  • 40
  • 64
  • the error shows you are calling it nw operation on ui thread (from 3.0+ not permited in strict mode) switch to async task – Athul Harikumar Sep 12 '12 at 13:09
  • refer this links http://stackoverflow.com/questions/8612406/android-os-networkonmainthreadexception-need-to-use-async-task , http://stackoverflow.com/questions/9413625/android-android-os-networkonmainthreadexception – rajeshwaran Sep 12 '12 at 13:13
  • check your image size and image name.. – Roadies Sep 12 '12 at 13:15

1 Answers1

0

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.

jlccaires
  • 77
  • 1
  • 3