1

I'm working on parsing JSON on BlackBerry using org.json.me, but I can't parsing the result. Simulator Console says: No Stack Trace

Here's my code to parsing JSON after receiving JSON string from my restclient

    try {
        JSONObject outer=new JSONObject(data);     
        JSONArray ja = outer.getJSONArray("status");
        JSONArray arr=ja.getJSONArray(0);               
        System.out.println(arr);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

And here's the piece code to get JSON from the server

public PromoThread(final String url, final ResponseCallback callback){
    Thread t = new Thread(new Runnable(){
        public void run() {
            waitScreen = new WaitPopupScreen();

            System.out.println("Log >> Promo thread run...");
            synchronized (UiApplication.getEventLock()){
                UiApplication.getUiApplication().pushScreen(waitScreen);
            }
            //network call
            try {
                conn = (HttpConnection) new ConnectionFactory().getConnection(url).getConnection();
                conn.setRequestMethod(HttpConnection.GET);
                conn.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");

                if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
                    in = conn.openInputStream();
                    // parser.parse(in, handler);
                    //buff.append(IOUtilities.streamToBytes(in));
                    //result = buff.toString();
                    results = new String(IOUtilities.streamToBytes(in));
                    //System.out.println("Log >> Result: " + results);
                    UiApplication.getUiApplication().invokeLater(
                            new Runnable() {
                                public void run() {
                                    //UiApplication.getUiApplication().popScreen(waitScreen);
                                    callback.callback(results, waitScreen);
                                }
                    }); 
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                    conn.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    //start thread
    t.start(); 
}

Thanks for your help

andriansandi
  • 89
  • 1
  • 16
  • 1
    It is an exception in your code. Use try/catch statement, to get a line where you get the exception. Do not use big blocks of try/catch, embrace in try-catch every line that potentially may throw an exception. Then analyze that line of code. It will give you an insight, what is going wrong. –  Oct 04 '12 at 12:33
  • You mean the exception when parsing JSON? – andriansandi Oct 04 '12 at 13:27
  • Is the data is valid on the line `JSONObject outer=new JSONObject(data);`? – Rupak Oct 04 '12 at 15:50
  • I mean all potential exceptions. JSON parsing exception, I/O exceptions, etc. –  Oct 04 '12 at 17:52
  • Possible duplicate of [NullPointerException in Java with no StackTrace](http://stackoverflow.com/questions/2411487/nullpointerexception-in-java-with-no-stacktrace) – Paul Sweatte Dec 12 '16 at 21:40

0 Answers0