Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

In this page you can find the example usage for org.json JSONException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:example.SendNumbers.java

/**
 * @param args/*from w w  w. jav a  2s  .co  m*/
 * @throws MalformedURLException
 */
public static void main(String[] args) throws MalformedURLException {

    AEONSDK sdk = new AEONSDK(Config.PUB_URL);

    for (int i = 0; i <= 500; i++) {
        JSONObject data = new JSONObject();
        try {
            data.put("number", i);
            System.out.println(data.toString());
            sdk.publish(data, new MyAEONCallbacks());
            TimeUnit.MICROSECONDS.sleep(200);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

From source file:com.ibm.mobilefirst.mobileedge.abstractmodel.GyroscopeData.java

@Override
public JSONObject asJSON() {
    JSONObject json = super.asJSON();

    try {//  ww w.  j a v a  2 s .co m
        JSONObject data = new JSONObject();
        data.put("x", x);
        data.put("y", y);
        data.put("z", z);
        json.put("gyroscope", data);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return json;
}

From source file:io.selendroid.server.SelendroidResponse.java

@Override
public String render() {
    JSONObject o = new JSONObject();
    try {/*  w w  w .  j  a va 2s.com*/
        if (sessionId != null) {
            o.put("sessionId", sessionId);
        }
        o.put("status", status);
        if (value != null) {
            o.put("value", value);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return o.toString();
}

From source file:pubsub.io.processing.Pubsub.java

/**
 * Hook up to a specific sub.//from   w ww.  j  a va  2 s .co m
 * 
 * @param sub
 */
public void sub(String sub) {
    try {
        t.write(PubsubParser.sub(sub).getBytes());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:pubsub.io.processing.Pubsub.java

/**
 * Unsubscribe the specified handler_callback.
 * /*w  ww. ja v  a 2  s  .com*/
 * @param handler_callback
 */
public void unsubscribe(Integer handler_callback) {
    // Remove the handler callback
    callbacks.remove(handler_callback);
    try {
        t.write(PubsubParser.unsubscribe(handler_callback).getBytes());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:pubsub.io.processing.Pubsub.java

/**
 * Publish a document to the connected sub.
 * //from  w w  w .ja  v  a  2 s . co  m
 * @param doc
 */
public void publish(JSONObject json_doc) {
    try {
        t.write(PubsubParser.publish(json_doc).getBytes());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:pubsub.io.processing.Pubsub.java

/**
 * Publish a document to the connected sub.
 * //w  w w  .  ja va2  s  .  co  m
 * @param doc
 */
public void publish(JSONArray json_doc) {
    try {
        t.write(PubsubParser.publish(json_doc).getBytes());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.googlecode.CallerLookup.Main.java

public void saveUserLookupEntries() {
    try {/* w ww.  j a  va2 s .  c  o m*/
        FileOutputStream file = getApplicationContext().openFileOutput(SAVED_FILE, MODE_PRIVATE);
        JSONArray userLookupEntries = new JSONArray();
        for (String lookupEntryName : mUserLookupEntries.keySet()) {
            try {
                userLookupEntries.put(mUserLookupEntries.get(lookupEntryName).toJSONObject());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        OutputStreamWriter content = new OutputStreamWriter(file);
        content.write(userLookupEntries.toString());
        content.flush();
        content.close();
        file.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ti.mobileapptracker.MobileapptrackerModule.java

private List<MATEventItem> convertToMATEventItems(Object[] arrItemMaps) {
    List<MATEventItem> listItems = new ArrayList<MATEventItem>();

    try {/*from w  w w .  j  a v  a 2 s. co  m*/
        JSONArray arr = new JSONArray(Arrays.toString(arrItemMaps));

        for (int i = 0; i < arr.length(); i++) {
            JSONObject item = arr.getJSONObject(i);

            String itemName = item.getString("item");
            int quantity = 0;
            double unitPrice = 0;
            double revenue = 0;
            String attribute1 = null;
            String attribute2 = null;
            String attribute3 = null;
            String attribute4 = null;
            String attribute5 = null;

            if (item.has("quantity")) {
                quantity = item.getInt("quantity");
            }
            if (item.has("unit_price")) {
                unitPrice = item.getDouble("unit_price");
            }
            if (item.has("revenue")) {
                revenue = item.getDouble("revenue");
            }

            if (item.has("attribute_sub1")) {
                attribute1 = item.getString("attribute_sub1");
            }
            if (item.has("attribute_sub2")) {
                attribute2 = item.getString("attribute_sub2");
            }
            if (item.has("attribute_sub3")) {
                attribute3 = item.getString("attribute_sub3");
            }
            if (item.has("attribute_sub4")) {
                attribute4 = item.getString("attribute_sub4");
            }
            if (item.has("attribute_sub5")) {
                attribute5 = item.getString("attribute_sub5");
            }

            MATEventItem eventItem = new MATEventItem(itemName, quantity, unitPrice, revenue, attribute1,
                    attribute2, attribute3, attribute4, attribute5);
            listItems.add(eventItem);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return listItems;
}

From source file:com.norman0406.slimgress.API.Interface.RequestResult.java

public static void handleRequest(JSONObject json, RequestResult result) {
    if (result == null)
        throw new RuntimeException("invalid result object");

    try {/*from ww  w. j av  a2  s .  c o  m*/
        // handle exception string if available
        String excString = json.optString("exception");
        if (excString.length() > 0)
            result.handleException(excString);

        // handle error code if available
        String error = json.optString("error");
        if (error.length() > 0)
            result.handleError(error);
        else if (json.has("error"))
            Log.w("RequestResult", "request contains an unknown error type");

        // handle game basket if available
        JSONObject gameBasket = json.optJSONObject("gameBasket");
        if (gameBasket != null)
            result.handleGameBasket(new GameBasket(gameBasket));

        // handle result if available
        JSONObject resultObj = json.optJSONObject("result");
        JSONArray resultArr = json.optJSONArray("result");
        String resultStr = json.optString("result");
        if (resultObj != null)
            result.handleResult(resultObj);
        else if (resultArr != null)
            result.handleResult(resultArr);
        else if (resultStr != null)
            result.handleResult(resultStr);
        else if (json.has("result"))
            Log.w("RequestResult", "request contains an unknown result type");

        result.finished();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}