Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:24:10+00:00 2026-06-08T12:24:10+00:00

I am new in BB trying to parse Json file and just want to

  • 0

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 No Application Instance and is also getting IllegalStateException. I use GET url method for it.
I Have also add permission in UiApplication like ..

UIApplicationScreen

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();

Here is MainScreen 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)) > 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());
                }
             }
          }
        }
    }

Update::

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)) > 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()
                     * > 0) { for (int i = 0; i < 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());
                    }
                }
            }
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:24:11+00:00Added an answer on June 8, 2026 at 12:24 pm

    Try this code –

    final ButtonField b=new ButtonField("JSON");
        add(b);
    
        FieldChangeListener listener=new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                if(field==b){
    
                    try {
                        String httpURL = "http://docs.blackberry.com/sampledata.json";  
                        HttpConnection httpConn;
                        httpConn = (HttpConnection) Connector.open(httpURL);
                        httpConn.setRequestMethod(HttpConnection.POST);
                        DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream());
                        byte[] request_body = httpURL.getBytes();
                        for (int i = 0; i < request_body.length; i++) {
                        _outStream.writeByte(request_body[i]);
                        }
                        DataInputStream _inputStream = new DataInputStream(
                        httpConn.openInputStream());
                        StringBuffer _responseMessage = new StringBuffer();
                        int ch;
                        while ((ch = _inputStream.read()) != -1) {
                        _responseMessage.append((char) ch);
                        }
                        String res = (_responseMessage.toString());
                        String responce = res.trim();
    
                        Dialog.alert(responce);
    
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    
                }
    
            }
        };
        b.setChangeListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I am trying to read a JSON file and parse it. I have this
I am trying to parse a JSON object in my android application and I
I am currently trying to parse a local JSON file on Webkit browsers and
I am trying to parse a Json file like this, generated by Exiftool: [{
I am trying to fetch a JSON file from my website and parse it.
I am new to iphone, i am trying to parse a webpage. In that
i am new to regex. I am trying to parse all contents inside curly
I'm trying to start an Intent for a navigation: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(google.navigation:q= + item.getPoint().getLatitudeE6()/1E6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.