title: Android JSONArray NullPointerException Cannot Evaluate JSONArray.toString()
body: <p>I'm building my first Android app and it requires pulling is JSON formatted data from a local web server.  The web server is up and running and I can see the returned data while debugging the Android app.  However, while trying to parse the data into a JSON Array, I keep hitting a NullPointerException at the last line of code.</p>
  
  <p>The call:</p>
  
  <pre><code>
          JSONParserTask jParser = new JSONParserTask();
          ArrayList> ResultsList = new ArrayList>();
          EditText etSoNo = (EditText) findViewById(R.id.txtSoNo);
          //String url = "http://xxx.xxx.xxx.xxx/api/SOLocLookup/" + etSoNo.getText();
          String url = "http://headers.jsontest.com/";
  
          try{
              DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
              HttpGet httpget = new HttpGet(url);
              httpget.setHeader("Content-type", "application/json");
              httpget.setHeader("Accept", "JSON");
  
              InputStream inputStream = null;
              String result = null;
  
              HttpResponse response = httpclient.execute(httpget);
              HttpEntity entity = response.getEntity();
  
              inputStream = entity.getContent();
              BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
              StringBuilder sb = new StringBuilder();
  
              String line = null;
              while ((line = reader.readLine()) != null)
              {
                  sb.append(line + "\n");
              }
  
              result = sb.toString();
  
              StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
              StrictMode.setThreadPolicy(policy);
  
              JSONArray jArray = new JSONArray(result);
  </code></pre>
  
  <p>At first I thought that maybe my API wasn't sending out a JSON formatted response, so you can see that I changed the call to a test JSON service: <a href="http://headers.jsontest.com/" rel="nofollow">http://headers.jsontest.com/</a></p>
  
  <p>The return data:</p>
  
  <blockquote>
    <p>{    "Accept-Language": "en-US,en;q=0.8",    "Host":
    "headers.jsontest.com",    "User-Agent": "Mozilla/5.0 (Windows NT 6.1;
    WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76
    Safari/537.36",    "Accept":
    "text/html,application/xhtml+xml,application/xml;q=0.9,<em>/</em>;q=0.8" }</p>
  </blockquote>
  
  <p>My LogCat:</p>
  
  <blockquote>
    <p>09-26 18:08:30.977       61-214/system_process I/ActivityManager:
    Starting: Intent {
    cmp=com.evs.sodscamera/.activity.SoMatlLookup.SoMatlLookup } from pid
    1034 09-26 18:08:31.997        61-99/system_process I/ActivityManager:
    Displayed com.evs.sodscamera/.activity.SoMatlLookup.SoMatlLookup:
    +913ms 09-26 18:09:11.748    1034-1034/com.evs.sodscamera D/dalvikvm: JDWP invocation returning with exceptObj=0x40589210
    (Ljava/lang/NullPointerException;)</p>
  </blockquote>
  
  <p>I'm really at a loss.  I'm sure that it's something so simple, but with my inexperience I just can't find it.</p>
  
  <p>Thanks!!</p>
  
  <p>-Greg</p>
  
  <p>Update 1:</p>
  
  <p>Changing the JSONArray to a JSONObject works for the data returned from the test website.  But when I go to retrieve my original data, it actually is stored as an Array.  I should have realized that earlier and not posted using bad test data.  My apologies.</p>
  
  <p>New Return Data:</p>
  
  <blockquote>
    <p>[{"SoNo":119152.0,"SoLn":1.00,"ItemID":"7075SHA6016","ItemDesc":"7075-T6
    ALCLAD SHEET
    .016\"","Size1":48.00000,"Size2":144.00000,"TagNo":62336.0,"Pcs":1.0,"Loc":"G0303"},{"SoNo":119152.0,"SoLn":1.00,"ItemID":"7075SHA6016","ItemDesc":"7075-T6
    ALCLAD SHEET
    .016\"","Size1":48.00000,"Size2":144.00000,"TagNo":67931.0,"Pcs":124.0,"Loc":"G0303"},{"SoNo":119152.0,"SoLn":1.00,"ItemID":"7075SHA6016","ItemDesc":"7075-T6
    ALCLAD SHEET
    .016\"","Size1":48.00000,"Size2":48.00000,"TagNo":68912.0,"Pcs":1.0,"Loc":"REM75"},{"SoNo":119152.0,"SoLn":1.00,"ItemID":"7075SHA6016","ItemDesc":"7075-T6
    ALCLAD SHEET
    .016\"","Size1":48.00000,"Size2":144.00000,"TagNo":69589.0,"Pcs":177.0,"Loc":"RECVG"},{"SoNo":119152.0,"SoLn":1.00,"ItemID":"7075SHA6016","ItemDesc":"7075-T6
    ALCLAD SHEET
    .016\"","Size1":48.00000,"Size2":48.00000,"TagNo":76493.0,"Pcs":1.0,"Loc":"REM75"},{"SoNo":119152.0,"SoLn":2.00,"ItemID":"2024SHA3125M","ItemDesc":"2024-T3
    ALCLAD SHEET .125\"
    MRS","Size1":48.00000,"Size2":144.00000,"TagNo":72070.0,"Pcs":12.0,"Loc":"H0108"},{"SoNo":119152.0,"SoLn":3.00,"ItemID":"177SH-016","ItemDesc":"T17/7
    SHEET .016\"<br>
    AMS-5528","Size1":36.00000,"Size2":120.00000,"TagNo":70031.0,"Pcs":1.0,"Loc":"S0504"},{"SoNo":119152.0,"SoLn":3.00,"ItemID":"177SH-016","ItemDesc":"T17/7
    SHEET
    .016\"","Size1":36.00000,"Size2":120.00000,"TagNo":76108.0,"Pcs":10.0,"Loc":""}]</p>
  </blockquote>
  
  <p>Thanks!!</p>