title: Parsing JSON data in Android App error
body: <p>In my Android app , i am trying to get popular media from instagram, i am using JSONParser class showed in this tutorial <a href="http://www.androidhive.info/2012/01/android-json-parsing-tutorial/" rel="nofollow">http://www.androidhive.info/2012/01/android-json-parsing-tutorial/</a> </p>
  
  <pre><code>public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
  
      // constructor
      public JSONParser() {}
  
      public JSONObject getJSONFromUrl(String url) {
        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpPost = new HttpGet(url);
  
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();          
        } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                  e.printStackTrace();
              }
  
          try {
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              json = sb.toString();
          } catch (Exception e) {
                Log.e("Buffer Error", "Error converting result " + e.toString());
            }
  
          // try parse the string to a JSON object
          try {
              jObj = new JSONObject(json);
          } catch (JSONException e) {
                Log.e("JSON Parser", "Error parsing data " + e.toString());
            }
  
          // return JSON String
          return jObj;
      }
  }
  </code></pre>
  
  <p>This is the the code i am trying to get to work: </p>
  
  <pre><code>private static  String urlInst = "https://api.instagram.com/v1/media/popular?client_id="+clientId;
  public static  void Func() {
      JSONParser jParser = new JSONParser();
      JSONObject json = jParser.getJSONFromUrl(urlInst);
      try {
      JSONArray pics = json.getJSONArray("data");
          for (int i = 0; i &lt; pics.length(); i++) { 
              JSONObject c=(JSONObject) pics.get(i);
              JSONObject user = c.getJSONObject("user");
              String name= user.getString("username");
              JSONObject img=c.getJSONObject("images");
              JSONObject thum=img.getJSONObject("thumbnail");
              String urlOfPic = thum.getString("url");                                  
          }
      } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
  }
  </code></pre>
  
  <p>But I am getting error :</p>
  
  <blockquote>
    <p>Buffer Error: Error converting result java.lang.NullPointerException</p>
    
    <p>JSON Parser Error parsing data org.json.JSONEXception: End of input at character 0 of</p>
  </blockquote>
  
  <p>I'm trying to figure out what is causing this error, any ideas? As far as I can see error is in this line. </p>
  
  <blockquote>
    <p>JSONObject json = jParser.getJSONFromUrl(urlInst); </p>
  </blockquote>
  
  <p>But I am beginner so I am not sure. Help will be apreciated. </p>
  
  <p>Full error log:</p>
  
  <blockquote>
    <p>09-08 16:49:22.343: E/Buffer Error(9981): Error converting result java.lang.NullPointerException
    09-08 16:49:22.343: E/JSON Parser(9981): Error parsing data org.json.JSONException: End of input at character 0 of 
    09-08 16:49:22.351: E/AndroidRuntime(9981): FATAL EXCEPTION: main
    09-08 16:49:22.351: E/AndroidRuntime(9981): java.lang.RuntimeException: Unable to start activity ComponentInfo{hr.zadatak.undabot.instag/hr.zadatak.undabot.instag.StartShowing}: java.lang.NullPointerException
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.os.Looper.loop(Looper.java:123)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread.main(ActivityThread.java:4668)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at java.lang.reflect.Method.invoke(Method.java:521)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at dalvik.system.NativeStart.main(Native Method)
    09-08 16:49:22.351: E/AndroidRuntime(9981): Caused by: java.lang.NullPointerException
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at hr.zadatak.undabot.instag.ListOfPhotos.LoadInstagramPictures(ListOfPhotos.java:51)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at hr.zadatak.undabot.instag.StartShowing.onCreate(StartShowing.java:16)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    09-08 16:49:22.351: E/AndroidRuntime(9981):     ... 11 more</p>
  </blockquote>