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

David Veres
  • 55
  • 1
  • 2
  • 7

1 Answers1

-1

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

Community
  • 1
  • 1
Deepak Goyal
  • 4,747
  • 2
  • 21
  • 46