title: issue with parsing JSON Data in Blackberry
body: <p>I am new in BB trying to parse Json file and just want to print the Json responce in a Dialog. But it raises an error regarding <code>No Application Instance</code> and is also getting <code>IllegalStateException</code>. I use <code>GET</code> url method for it.
  I Have also add permission in <code>UiApplication</code> like ..</p>
  
  <p><strong>UIApplicationScreen</strong></p>
  
  
  
  <pre><code>public static void main(String[] args) {
      ApplicationPermissions permRequest = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
      permRequest = new ApplicationPermissions();
      permRequest.addPermission( ApplicationPermissions.PERMISSION_INTERNET );
      ApplicationPermissionsManager.getInstance().invokePermissionsRequest( permRequest );
  
      UiFunApplication app = new UiFunApplication();
      app.enterEventDispatcher();
  </code></pre>
  
  <p><strong>Here is MainScreen Code....</strong></p>
  
  <pre><code>import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Vector;
  
  import javax.microedition.io.Connector;
  import javax.microedition.io.HttpConnection;
  
  import net.rim.device.api.applicationcontrol.ApplicationPermissions;
  import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
  import net.rim.device.api.ui.component.Dialog;
  import net.rim.device.api.ui.container.MainScreen;
  
  import com.rim.samples.jsonme.cakeorder.org.json.me.JSONArray;
  import com.rim.samples.jsonme.cakeorder.org.json.me.JSONObject;
  
  public class UiMainscreen extends MainScreen  {
  
      public UiMainscreen() {
          Dialog.alert("asdasd");
           HttpConnection conn = null;
            InputStream in = null;
            ByteArrayOutputStream out = null;
            try {
             //  String url = "http://api.twitter.com/1/users/show.json?screen_name=Kaka";
               String url = "http://docs.blackberry.com/sampledata.json";
  
               conn = (HttpConnection) Connector.open(url, Connector.READ);
               conn.setRequestMethod(HttpConnection.GET);
  
               int code = conn.getResponseCode();
               if (code == HttpConnection.HTTP_OK) {
                  in = conn.openInputStream();
                  out = new ByteArrayOutputStream();
                  byte[] buffer = new byte[in.available()];
                  int len = 0;
                  while ((len = in.read(buffer)) &gt; 0) {
                     out.write(buffer);
                  }
                  out.flush();
                  String response = new String(out.toByteArray());
                  Dialog.alert("response is ::"+response);
                  } catch (Exception e) {
               Dialog.alert(e.getMessage());
            } finally {
               if (out != null) {
                  try {
                      out.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      Dialog.alert(e.getMessage());
                  }
               }
               if (in != null) {
                  try {
                      in.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      Dialog.alert(e.getMessage());
                  }
               }
               if (conn != null) {
                  try {
                      conn.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      Dialog.alert(e.getMessage());
                  }
               }
            }
          }
      }
  </code></pre>
  
  <p><strong>Update::</strong> </p>
  
  <pre><code>import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Vector;
  
  import javax.microedition.io.Connector;
  import javax.microedition.io.HttpConnection;
  
  import net.rim.device.api.applicationcontrol.ApplicationPermissions;
  import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
  import net.rim.device.api.ui.Field;
  import net.rim.device.api.ui.FieldChangeListener;
  import net.rim.device.api.ui.component.ButtonField;
  import net.rim.device.api.ui.component.CheckboxField;
  import net.rim.device.api.ui.component.Dialog;
  import net.rim.device.api.ui.container.MainScreen;
  
  import com.rim.samples.jsonme.cakeorder.org.json.me.JSONArray;
  import com.rim.samples.jsonme.cakeorder.org.json.me.JSONObject;
  
  public class UiMainscreen extends MainScreen implements FieldChangeListener {
  
      public UiMainscreen() {
          ButtonField loginButton;
  
          loginButton = new ButtonField("Go", ButtonField.CONSUME_CLICK);
          loginButton.setChangeListener(this);
  
          add(loginButton);
  
      }
  
      public void fieldChanged(Field field, int context) {
          // TODO Auto-generated method stub
          if (field instanceof ButtonField) {
  
              Dialog.alert("Message");
              HttpConnection conn = null;
              InputStream in = null;
              ByteArrayOutputStream out = null;
              try {
                  // String url =
                  // "http://api.twitter.com/1/users/show.json?screen_name=Kaka";
                  String url = "http://docs.blackberry.com/sampledata.json";
  
                  conn = (HttpConnection) Connector.open(url, Connector.READ);
                  conn.setRequestMethod(HttpConnection.GET);
  
                  int code = conn.getResponseCode();
                  if (code == HttpConnection.HTTP_OK) {
                      in = conn.openInputStream();
                      out = new ByteArrayOutputStream();
                      byte[] buffer = new byte[in.available()];
                      int len = 0;
                      while ((len = in.read(buffer)) &gt; 0) {
                          out.write(buffer);
                      }
                      out.flush();
                      String response = new String(out.toByteArray());
                      Dialog.alert("response is ::" + response);
  
                      /*
                       * JSONObject resObject = new JSONObject(response); String
                       * key = resObject.getString("vehicleType");
                       * 
                       * Vector resultsVector = new Vector(); JSONArray jsonArray
                       * = resObject.getJSONArray("name"); if (jsonArray.length()
                       * &gt; 0) { for (int i = 0; i &lt; jsonArray.length();i++) {
                       * Vector elementsVector = new Vector(); JSONObject jsonObj
                       * = jsonArray.getJSONObject(i);
                       * elementsVector.addElement(jsonObj
                       * .getString("experiencePoints"));
                       * elementsVector.addElement
                       * (jsonObj.getString("Insert Json Array Element Key2"));
                       * resultsVector.addElement(elementsVector); } }
                       */
                  }
              } catch (Exception e) {
                  Dialog.alert(e.getMessage());
              } finally {
                  if (out != null) {
                      try {
                          out.close();
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                          Dialog.alert(e.getMessage());
                      }
                  }
                  if (in != null) {
                      try {
                          in.close();
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                          Dialog.alert(e.getMessage());
                      }
                  }
                  if (conn != null) {
                      try {
                          conn.close();
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                          Dialog.alert(e.getMessage());
                      }
                  }
              }
          }
  
      }
  }
  </code></pre>