Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.hdezninirola.fantasywithdrawer.utils.AbstractGetNameTask.java

@Override
protected Void doInBackground(Void... params) {
    try {// w  w  w.  j a  v  a 2 s .c o  m
        fetchNameFromProfileServer();
    } catch (IOException ex) {
        onError("Following Error occured, please try again. " + ex.getMessage(), ex);
    } catch (JSONException e) {
        onError("Bad response: " + e.getMessage(), e);
    }
    return null;
}

From source file:org.pluginporo.barcodescan.BarcodeScanPlugin.java

private JSONObject getScannedInfo(String barcode) {
    DriverLicense dl = parseDL(barcode);
    JSONObject obj = new JSONObject();
    try {//from   w  ww. j a  v a2s  .  c o m
        obj.put("barcode", barcode);
        if (dl != null) {
            obj.put("dln", dl.getDriverLicenseNumber());
            obj.put("first_name", dl.getFirstName());
            obj.put("last_name", dl.getLastName());
        }
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return obj;
}

From source file:org.creativecommons.thelist.fragments.GalleryFragment.java

public void refreshItems() {
    if (!mCurrentUser.isTempUser()) {
        mRequestMethods.getUserPhotos(new RequestMethods.ResponseCallback() {
            @Override// w ww. j a v a  2 s .  c  o m
            public void onSuccess(JSONArray response) {
                Log.v(TAG, " > getUserPhotos > onSuccess" + response.toString());
                mPhotoList.clear();

                for (int i = 0; i < response.length(); i++) {
                    GalleryItem galleryItem = new GalleryItem();

                    try {
                        JSONObject singlePhotoItem = response.getJSONObject(i);
                        String photoUrl = singlePhotoItem.getString(ApiConstants.USER_PHOTO_URL);
                        Log.v(TAG, photoUrl);
                        galleryItem.setUrl(photoUrl);

                        if (photoUrl == null) {
                            galleryItem.setProgress(true);
                        }
                        mPhotoList.add(galleryItem);
                    } catch (JSONException e) {
                        Log.v(TAG, e.getMessage());
                    }
                }

                Log.v(TAG, "PHOTOLIST RESPONSE " + mPhotoList);

                mProgressBar.setVisibility(View.INVISIBLE);

                if (mPhotoList.size() == 0) {
                    //TODO: show textView
                    mEmptyView.setText(R.string.empty_gallery_label_logged_in);
                    mEmptyView.setVisibility(View.VISIBLE);
                    Log.v(TAG, "VIEW IS EMPTY");
                } else {
                    //TODO: hide textView
                    mEmptyView.setVisibility(View.GONE);
                    Log.v(TAG, "VIEW HAS PHOTO ITEMS");
                    Collections.reverse(mPhotoList);
                    mGalleryAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFail(VolleyError error) {
                Log.d(TAG, "> getUserPhotos > onFail: " + error.toString());
            }
        });
    } else {
        mEmptyView.setText(mContext.getString(R.string.empty_gallery_label_temp));
        mEmptyView.setVisibility(View.VISIBLE);
    }
}

From source file:com.adf.bean.AbsBean.java

/**
 * IMPORT// w  ww  .j  av  a  2s  .c  o m
 * */
public void setValueByColumn(String col, String val) throws IllegalArgumentException {
    try {
        Field f = getClass().getDeclaredField(col);
        Class<?> cls = f.getType();
        f.setAccessible(true);
        if (cls.isArray()) {
            JSONArray arr;
            try {
                arr = new JSONArray(val);
                setArrayColumn(col, arr);
            } catch (JSONException e) {
            }
            return;
        }
        if ((int.class == cls) || (Integer.class == cls)) {
            int ival = Integer.parseInt(val);
            f.set(this, ival);
        } else if ((long.class == cls) || (Long.class == cls)) {
            long lval = Long.parseLong(val);
            f.set(this, lval);
        } else if ((float.class == cls) || (Float.class == cls)) {
            float fval = Float.parseFloat(val);
            f.set(this, fval);
        } else if ((short.class == cls) || (Short.class == cls)) {
            short sval = Short.parseShort(val);
            f.set(this, sval);
        } else if ((double.class == cls) || (Double.class == cls)) {
            double dval = Double.parseDouble(val);
            f.set(this, dval);
        } else if ((byte.class == cls) || (Byte.class == cls)) {
            byte bval = Byte.parseByte(val);
            f.set(this, bval);
        } else if ((boolean.class == cls) || (Boolean.class == cls)) {
            boolean bval = Boolean.parseBoolean(val);
            f.set(this, bval);
        } else if (char.class == cls) {
            char cval = val.charAt(0);
            f.set(this, cval);
        } else {
            Constructor<?> cons = cls.getDeclaredConstructor(String.class);
            cons.setAccessible(true);
            Object obj = cons.newInstance(val);
            f.set(this, obj);
        }
    } catch (NoSuchFieldException e) {
        LogUtil.err("setValueByColumn NoSuchFieldException, col " + col + " not exist!!!");
    } catch (IllegalAccessException e) {
        LogUtil.err("setValueByColumn IllegalAccessException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (IllegalArgumentException e) {
        LogUtil.err("setValueByColumn IllegalArgumentException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (NoSuchMethodException e) {
        LogUtil.err("setValueByColumn NoSuchMethodException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (InstantiationException e) {
        LogUtil.err("setValueByColumn InstantiationException, col " + col + " :" + e.getMessage());
        //throw e;
    } catch (InvocationTargetException e) {
        LogUtil.err("setValueByColumn InvocationTargetException, col " + col + " :" + e.getMessage());
        //throw e;
    }
}

From source file:face4j.response.StatusResponseImpl.java

public StatusResponseImpl(String json) throws FaceClientException {
    super(json);//from  w  w  w  .j  a  va 2 s .  com

    try {
        user_status = toUserStatusList(response.getJSONArray("user_statuses"));
    }

    catch (JSONException jex) {
        logger.error("Error adaption user_status: " + jex.getMessage(), jex);

        throw new FaceClientException(jex);
    }
}

From source file:com.relurori.sandbox.spreadsheet.gdata.AbstractGetNameTask.java

@Override
protected Void doInBackground(Void... params) {
    Log.d(TAG, "doInBackground");
    try {/* w w  w .j a  v a2s  . c o m*/
        // do work on server
        fetchNameFromProfileServer();
        fetchSpreadsheetListFromServer();
    } catch (IOException ex) {
        onError("Following Error occured, please try again. " + ex.getMessage(), ex);
    } catch (JSONException e) {
        onError("Bad response: " + e.getMessage(), e);
    }
    return null;
}

From source file:com.facebook.share.internal.LegacyNativeDialogParameters.java

public static Bundle create(UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");

    Bundle nativeParams = null;//from w w  w.j a  va2  s  . c  o m
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(photoContent, callId);

        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        nativeParams = create(videoContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(callId, openGraphContent);

            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException(
                    "Unable to create a JSON Object from the provided ShareOpenGraphContent: "
                            + e.getMessage());
        }
    }

    return nativeParams;
}

From source file:com.aokyu.dev.pocket.PocketClient.java

public AccessToken authenticate(RequestToken requestToken)
        throws IOException, InvalidRequestException, PocketException {
    String endpoint = PocketServer.getEndpoint(RequestType.OAUTH_AUTHORIZE);
    URL requestUrl = new URL(endpoint);
    HttpHeaders headers = new HttpHeaders();
    headers.put(HttpHeader.CONTENT_TYPE, ContentType.JSON_WITH_UTF8.get());
    headers.put(HttpHeader.X_ACCEPT, ContentType.JSON.get());
    headers.put(HttpHeader.HOST, requestUrl.getHost());

    HttpParameters parameters = new HttpParameters();
    parameters.put(AuthRequestParameter.CONSUMER_KEY, mConsumerKey.get());
    parameters.put(AuthRequestParameter.CODE, requestToken.get());

    HttpRequest request = new HttpRequest(HttpMethod.POST, requestUrl, headers, parameters);

    HttpResponse response = null;/* w ww. j a  va2s . co m*/
    AccessToken accessToken = null;
    try {
        response = mClient.execute(request);
        if (response.getStatusCode() == HttpURLConnection.HTTP_OK) {
            JSONObject jsonObj = response.getResponseAsJSONObject();
            accessToken = new AccessToken(jsonObj);
        } else {
            ErrorResponse error = new ErrorResponse(response);
            mErrorHandler.handleResponse(error);
        }
    } catch (JSONException e) {
        throw new PocketException(e.getMessage());
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }

    return accessToken;
}

From source file:com.aokyu.dev.pocket.PocketClient.java

private RequestToken retrieveRequestToken() throws IOException, InvalidRequestException, PocketException {
    String endpoint = PocketServer.getEndpoint(RequestType.OAUTH_REQUEST);
    URL requestUrl = new URL(endpoint);
    HttpHeaders headers = new HttpHeaders();
    headers.put(HttpHeader.CONTENT_TYPE, ContentType.JSON_WITH_UTF8.get());
    headers.put(HttpHeader.X_ACCEPT, ContentType.JSON.get());
    headers.put(HttpHeader.HOST, requestUrl.getHost());

    HttpParameters parameters = new HttpParameters();
    parameters.put(AuthRequestParameter.CONSUMER_KEY, mConsumerKey.get());
    parameters.put(AuthRequestParameter.REDIRECT_URI, PocketUtils.getRedirectUri(mConsumerKey));

    HttpRequest request = new HttpRequest(HttpMethod.POST, requestUrl, headers, parameters);

    HttpResponse response = null;//from  ww w .ja  v  a  2  s .  c om
    RequestToken requestToken = null;
    try {
        response = mClient.execute(request);
        if (response.getStatusCode() == HttpURLConnection.HTTP_OK) {
            JSONObject jsonObj = response.getResponseAsJSONObject();
            requestToken = new RequestToken(jsonObj);
        } else {
            ErrorResponse error = new ErrorResponse(response);
            mErrorHandler.handleResponse(error);
        }
    } catch (JSONException e) {
        throw new PocketException(e.getMessage());
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }

    return requestToken;
}

From source file:com.aokyu.dev.pocket.PocketClient.java

public AddResponse add(AccessToken accessToken, AddRequest addRequest)
        throws IOException, InvalidRequestException, PocketException {
    String endpoint = PocketServer.getEndpoint(RequestType.ADD);
    URL requestUrl = new URL(endpoint);
    HttpHeaders headers = new HttpHeaders();
    headers.put(HttpHeader.CONTENT_TYPE, ContentType.JSON_WITH_UTF8.get());
    headers.put(HttpHeader.X_ACCEPT, ContentType.JSON.get());
    headers.put(HttpHeader.HOST, requestUrl.getHost());

    addRequest.put(AddRequest.Parameter.ACCESS_TOKEN, accessToken.get());
    addRequest.put(AddRequest.Parameter.CONSUMER_KEY, mConsumerKey.get());

    HttpParameters parameters = addRequest.getHttpParameters();

    HttpRequest request = new HttpRequest(HttpMethod.POST, requestUrl, headers, parameters);

    HttpResponse response = null;//from w ww .ja  v  a2  s.  co m
    JSONObject jsonObj = null;
    Map<String, List<String>> responseHeaders = null;
    try {
        response = mClient.execute(request);
        if (response.getStatusCode() == HttpURLConnection.HTTP_OK) {
            jsonObj = response.getResponseAsJSONObject();
            responseHeaders = response.getHeaderFields();
        } else {
            ErrorResponse error = new ErrorResponse(response);
            mErrorHandler.handleResponse(error);
        }
    } catch (JSONException e) {
        throw new PocketException(e.getMessage());
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }

    AddResponse addResponse = null;
    if (jsonObj != null) {
        try {
            addResponse = new AddResponse(jsonObj, responseHeaders);
        } catch (JSONException e) {
            throw new PocketException(e.getMessage());
        }
    }

    return addResponse;
}