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:com.grarak.kerneladiutor.utils.database.ProfileDB.java

public int updateDB(Context context) {
    ProfileDB profileDB = new ProfileDB(context);
    int result = 0;

    List<ProfileDB.ProfileItem> profileItems = profileDB.getAllProfiles();
    for (int i = 0; i < profileItems.size(); i++) {
        JSONObject temp = profileItems.get(i).getItem();
        if (profileItems.get(i).getID().equals("111")) {
            try {
                temp.put("id", UUID.randomUUID());
                putItem(temp);//from   w ww . j a  v  a  2s  .co  m
                profileDB.commit();
                result = 1;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
    return result;
}

From source file:com.google.example.ads.customevents.impl.iab.IabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally.//  ww w. java2s . c o  m
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkSetupDone("handleActivityResult");

    // end of async purchase operation
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        Purchase purchase = null;
        try {
            purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                result = new IabResult(IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                if (mPurchaseListener != null)
                    mPurchaseListener.onIabPurchaseFinished(result, purchase);
                return true;
            }
            logDebug("Purchase signature successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.phelps.liteweibo.model.weibo.CommentList.java

public static CommentList parse(String jsonString) {
    if (TextUtils.isEmpty(jsonString)) {
        return null;
    }//from  www. j  a va2s. c  om

    CommentList comments = new CommentList();
    try {
        JSONObject jsonObject = new JSONObject(jsonString);
        comments.previous_cursor = jsonObject.optString("previous_cursor", "0");
        comments.next_cursor = jsonObject.optString("next_cursor", "0");
        comments.total_number = jsonObject.optInt("total_number", 0);

        JSONArray jsonArray = jsonObject.optJSONArray("comments");
        if (jsonArray != null && jsonArray.length() > 0) {
            int length = jsonArray.length();
            comments.commentList = new ArrayList<Comment>(length);
            for (int ix = 0; ix < length; ix++) {
                comments.commentList.add(Comment.parse(jsonArray.optJSONObject(ix)));
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return comments;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java

public JSONObject mergeRaw(JSONObject objData, byte[] raw) {
    try {/*from w  w  w. j  av  a2  s .  c  o m*/
        if (raw != null)
            objData = objData.put(DATA, Base64.encodeToString(raw, false));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return objData;
}

From source file:com.sdspikes.fireworks.FireworksTurn.java

public JSONObject getJSONObject() {
    JSONObject retVal = new JSONObject();

    try {/*from ww w  . j  a v  a 2s .  c o  m*/
        retVal.put("state", state.getJSONObject());
        retVal.put("turn", turnCounter);

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return retVal;
}

From source file:com.sdspikes.fireworks.FireworksTurn.java

static public FireworksTurn unpersist(JSONObject obj) {
    FireworksTurn retVal = new FireworksTurn();

    try {/* w ww .  ja v  a  2 s .  c om*/
        if (!obj.has("state")) {
            return null;
        } else {
            retVal.state = new GameState(obj.getJSONObject("state"));
        }
        if (obj.has("turn")) {
            retVal.turnCounter = obj.getInt("turn");
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return retVal;
}

From source file:com.intel.xdk.facebook.IntelXDKFacebook.java

private Bundle JSONtoBundle(JSONObject jsonObj) {
    Bundle params = new Bundle();
    Iterator<?> iter = jsonObj.keys();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        String value;/*w  w w.jav  a2 s.c  o  m*/
        try {
            value = jsonObj.getString(key);
            params.putString(key, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return params;
}

From source file:com.intel.xdk.facebook.IntelXDKFacebook.java

private JSONObject BundleToJSON(Bundle bundleObj) {
    JSONObject jsonObj = new JSONObject();

    Object[] keys = bundleObj.keySet().toArray();

    for (int i = 0; i < keys.length; i++) {
        String key = (String) keys[i];
        try {//from   w w w.  j  a  va 2s . co  m
            jsonObj.put(key, bundleObj.get(key));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return jsonObj;
}

From source file:com.intel.xdk.facebook.IntelXDKFacebook.java

@JavascriptInterface
public void requestWithRestAPI(String[] arguments) {
    if (busy) {//from  w w w .  jav a  2  s .  co m
        sendBusyEvent();
        return;
    }

    if (!session.isOpened()) {
        currentCommand = REQ_REST_API;
        currentCommandArguments = arguments;
        login(defaultLoginPermissions);
        return;
    } else {
        busy = true;
    }

    String command = arguments[0].replace("\"", "");
    String method = arguments[1].replace("\"", "");
    String parameters = arguments[2];

    JSONObject json = new JSONObject();
    try {
        json = new JSONObject(parameters);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //      try {
    //         json.put("method", "auth.expireSession");
    //      } catch (JSONException e1) {
    //         // TODO Auto-generated catch block
    //         e1.printStackTrace();
    //      }

    Bundle params = new Bundle();
    //      params.putString("caption", "caption");
    //      params.putString("message", "message");
    //      params.putString("link", "link_url");
    //      params.putString("picture", "picture_url");
    //params.putString("fields", "id,name,picture");

    //MAKE THE REQUEST
    //mAsyncRunner.request(null, JSONtoBundle(json), method, new FBApiRequestListener(),true);
    Request restRequest = Request.newRestRequest(session, command, JSONtoBundle(json),
            (method.toUpperCase().equals("GET")) ? HttpMethod.GET : HttpMethod.POST);
    //Request restRequest = Request.newRestRequest(session, "me/" + command, params, HttpMethod.POST);
    restRequest.setCallback(new Request.Callback() {

        @Override
        public void onCompleted(Response response) {
            FacebookRequestError error = response.getError();
            if (error != null) {
                String js = String.format(
                        "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=false;e.error='%s';e.raw='';e.data={};document.dispatchEvent(e);",
                        error.toString());
                //webView.loadUrl(js);
                injectJS(js);
                resetFBStatus();
                return;
                //                 if (error instanceof FacebookOperationCanceledException) {
                //                 }
                //                 else {
                //                    
                //                 }
            } else if (session == Session.getActiveSession()) {
                String responsestr = response.toString().replaceAll("'", "\\\\'");
                responsestr = responsestr.replaceAll("\"", "\\\\\"");

                String js = String.format(
                        "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=true;e.raw='%s';e.data={};try{e.data=JSON.parse(e.raw);}catch(ex){}e.error='';document.dispatchEvent(e);",
                        responsestr);
                //webView.loadUrl(js);
                injectJS(js);
                resetFBStatus();
                return;
            }
        }
    });
    //Request.executeBatchAsync(restRequest);
    restRequest.executeAndWait();
}

From source file:com.intel.xdk.facebook.IntelXDKFacebook.java

@JavascriptInterface
public void requestWithGraphAPI(String[] arguments)// path, String method, String parameters)
{
    if (busy) {/*from   w  w w .  j  ava  2s  .  co m*/
        sendBusyEvent();
        return;
    }

    if (!session.isOpened()) {
        currentCommand = REQ_GRAPH_API;
        currentCommandArguments = arguments;
        login(defaultLoginPermissions);
        return;
    } else {
        busy = true;
    }

    final String path = arguments[0];
    String method = arguments[1];
    String parameters = arguments[2];

    JSONObject json = new JSONObject();
    try {
        json = new JSONObject(parameters);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final JSONObject finalJson = json;

    cordova.getThreadPool().execute(new Runnable() {
        public void run() {

            Request graphRequest = Request.newGraphPathRequest(session, path, new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        String js = String.format(
                                "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=false;e.error='%s';e.raw='';e.data={};document.dispatchEvent(e);",
                                error.toString());
                        //webView.loadUrl(js);
                        injectJS(js);
                        resetFBStatus();
                        return;
                    } else if (session == Session.getActiveSession()) {
                        GraphObject graphObject = response.getGraphObject();
                        JSONArray array;

                        if (graphObject != null) {
                            JSONObject jsonObject = graphObject.getInnerJSONObject();

                            String responsestr = jsonObject.toString().replaceAll("'", "\\\\'");
                            responsestr = responsestr.replaceAll("\"", "\\\\\"");

                            String js = String.format(
                                    "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=true;e.raw='%s';e.data={};try{e.data=JSON.parse(e.raw);}catch(ex){}e.error='';document.dispatchEvent(e);",
                                    responsestr);
                            //webView.loadUrl(js);
                            injectJS(js);
                            resetFBStatus();
                            return;
                        } else {
                            String js = String.format(
                                    "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=false;e.error='%s';e.raw='';e.data={};document.dispatchEvent(e);",
                                    "There was a problem with the FB graph call.");
                            //webView.loadUrl(js);
                            injectJS(js);
                            resetFBStatus();
                            return;
                        }

                    }
                }
            });
            Bundle params = JSONtoBundle(finalJson);
            //params.putString("fields", "name,first_name,last_name");
            graphRequest.setParameters(params);
            graphRequest.executeAndWait();

        }
    });
}