-3

I'm trying to read JSON data form a URL, and currently i got this code snippet inside my onCreate method in my MainActivity class:

try {
        URL url = new URL("https://bugzilla.mozilla.org/rest/bug/35");

        try{

            InputStream in = url.openStream();

            JsonReader reader = new JsonReader(new InputStreamReader(in));

            // more will be there...

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

When I run the app on a virtual device, it says that the program is stopped, it can't even start it. Maybe I'm trying to read the data in a wrong way. The most important thing, is that I want to read JSON data from URL. I also added the INTERNET permission to the aplication, but it didn't help.

2
  • 2
    stacktrace. read it. Commented Sep 18, 2015 at 22:10
  • Are you running this on the UI thread? Commented Sep 18, 2015 at 22:16

1 Answer 1

-1

Use AsyncTask to perform network operation and For connecting to url use UrlConnection.
for example see this thread

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, this is what i wanted to get :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.