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.aliyun.openservices.odps.console.pub.WhoamiCommand.java

protected void cOutWhoami(String jsonResult) throws ODPSConsoleException {

    try {//from   w ww  .  jav a  2 s .  c om
        JSONObject js = new JSONObject(jsonResult);

        if (js.has("DisplayName")) {
            getWriter().writeResult("Name: " + js.getString("DisplayName"));
        }

        getWriter().writeResult("End_Point: " + getContext().getEndpoint());
        getWriter().writeResult("Project: " + getContext().getProjectName());

    } catch (JSONException e) {
        throw new ODPSConsoleException("parse whoami error:" + e.getMessage());
    }
}

From source file:com.example.android.uamp.playback.CastPlayback.java

@Override
public void play(QueueItem item) {
    try {//from  w ww  .java  2s  . c  o m
        loadMedia(item.getDescription().getMediaId(), true);
        mState = PlaybackStateCompat.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (JSONException e) {
        LogHelper.e(TAG, "Exception loading media ", e, null);
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.example.android.uamp.playback.CastPlayback.java

@Override
public void pause() {
    try {/*from   ww w. j a v  a 2s. c om*/
        if (mRemoteMediaClient.hasMediaSession()) {
            mRemoteMediaClient.pause();
            mCurrentPosition = (int) mRemoteMediaClient.getApproximateStreamPosition();
        } else {
            loadMedia(mCurrentMediaId, false);
        }
    } catch (JSONException e) {
        LogHelper.e(TAG, e, "Exception pausing cast playback");
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.example.android.uamp.playback.CastPlayback.java

@Override
public void seekTo(int position) {
    if (mCurrentMediaId == null) {
        if (mCallback != null) {
            mCallback.onError("seekTo cannot be calling in the absence of mediaId.");
        }//  w w  w. j  av  a2  s  . c  om
        return;
    }
    try {
        if (mRemoteMediaClient.hasMediaSession()) {
            mRemoteMediaClient.seek(position);
            mCurrentPosition = position;
        } else {
            mCurrentPosition = position;
            loadMedia(mCurrentMediaId, false);
        }
    } catch (JSONException e) {
        LogHelper.e(TAG, e, "Exception pausing cast playback");
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.neka.cordova.inappbrowser.InAppChromeClient.java

/**
 * Tell the client to display a prompt dialog to the user.
 * If the client returns true, WebView will assume that the client will
 * handle the prompt dialog and call the appropriate JsPromptResult method.
 *
 * The prompt bridge provided for the InAppBrowser is capable of executing any
 * oustanding callback belonging to the InAppBrowser plugin. Care has been
 * taken that other callbacks cannot be triggered, and that no other code
 * execution is possible.//  w  ww  .  java2  s . c o m
 *
 * To trigger the bridge, the prompt default value should be of the form:
 *
 * gap-iab://<callbackId>
 *
 * where <callbackId> is the string id of the callback to trigger (something
 * like "InAppBrowser0123456789")
 *
 * If present, the prompt message is expected to be a JSON-encoded value to
 * pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
 *
 * @param view
 * @param url
 * @param message
 * @param defaultValue
 * @param result
 */
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
        JsPromptResult result) {
    // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
    if (defaultValue != null && defaultValue.startsWith("gap")) {
        if (defaultValue.startsWith("gap-iab://")) {
            PluginResult scriptResult;
            String scriptCallbackId = defaultValue.substring(10);
            if (scriptCallbackId.startsWith("InAppBrowser")) {
                if (message == null || message.length() == 0) {
                    scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
                } else {
                    try {
                        scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
                    } catch (JSONException e) {
                        scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
                    }
                }
                this.webView.sendPluginResult(scriptResult, scriptCallbackId);
                result.confirm("");
                return true;
            }
        } else {
            // Anything else with a gap: prefix should get this message
            LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
            result.cancel();
            return true;
        }
    }
    return false;
}

From source file:br.com.great.util.OperacoesJSON.java

/**
 * Mtodo responsvel por receber um conjunto de chaves com valores retornar objetos json
 * @param key String[]//from w  w w  .  j  a  v  a2s  . c  o  m
 * @param value String[]
 * @return JSONObject
 */
public JSONObject toJSONObject(String[] key, String[] value) {
    JSONObject jobj = new JSONObject();
    int i = 0;
    try {
        for (String chave : key) {
            jobj.put(chave, value[i]);
            i++;
        }
    } catch (JSONException ex) {
        System.err.println("Erro toJSONObject:" + ex.getMessage());
    }
    return jobj;
}

From source file:br.com.great.util.OperacoesJSON.java

public JSONObject toJSONObject(String key, String value) {
    JSONObject jobj = new JSONObject();
    try {/*from   w  ww.  ja v a 2s.  c  o  m*/
        jobj.put(key, value);
    } catch (JSONException ex) {
        System.err.println("Erro toJSONObject:" + ex.getMessage());
    }
    return jobj;
}

From source file:br.com.great.util.OperacoesJSON.java

/**
 * Mtodo responsvel por receber jsonArray e retornar objetos json da posicao X
 * @param json JSONArray/*  w ww  .j av  a 2 s .co m*/
 * @param posObjeto int
 * @return JSONObject
 */
public JSONObject toJSONObject(JSONArray json, int posObjeto) {
    JSONObject jobj = null;
    try {
        jobj = json.getJSONObject(posObjeto);
    } catch (JSONException ex) {
        System.err.println("Erro toJSONObject:" + ex.getMessage());
    }
    return jobj;
}

From source file:br.com.great.util.OperacoesJSON.java

/**
 * Mtodo responsvel por receber jsonArray e retornar um item do objeto json da posicao X
 * @param json JSONArray/*from w ww.j  a  v  a2  s  .  c  o  m*/
 * @param posObjeto int
 * @param key String
 * @return String 
 */
public String toJSONObject(JSONArray json, int posObjeto, String key) {
    String value = "";
    try {
        JSONObject jobj = json.getJSONObject(posObjeto);
        value = jobj.getString(key);
    } catch (JSONException ex) {
        System.err.println("Error toJSONObject:" + ex.getMessage());
    }
    return value;
}

From source file:org.wso2.iot.system.service.SystemService.java

/**
 * Upgrading device firmware over the air (OTA).
 *//* w ww  . j a v  a  2  s.  co m*/
public void upgradeFirmware(final boolean isStatusCheck) {
    Log.i(TAG, "An upgrade has been requested");

    Preference.putBoolean(context, context.getResources().getString(R.string.firmware_status_check_in_progress),
            isStatusCheck);
    Preference.putString(context, context.getResources().getString(R.string.firmware_download_progress),
            String.valueOf(DEFAULT_STATE_INFO_CODE));
    Preference.putInt(context, context.getResources().getString(R.string.operation_id), operationId);

    String schedule = null;
    String server;
    if (command != null && !command.trim().isEmpty()) {
        try {
            JSONObject upgradeData = new JSONObject(command);
            if (!upgradeData.isNull(context.getResources().getString(R.string.alarm_schedule))) {
                schedule = (String) upgradeData.get(context.getResources().getString(R.string.alarm_schedule));
            }

            boolean isAutomaticRetry = !Preference.hasPreferenceKey(context,
                    context.getResources().getString(R.string.firmware_upgrade_automatic_retry))
                    || Preference.getBoolean(context,
                            context.getResources().getString(R.string.firmware_upgrade_automatic_retry));
            if (!upgradeData
                    .isNull(context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) {
                isAutomaticRetry = upgradeData.getBoolean(
                        context.getResources().getString(R.string.firmware_upgrade_automatic_retry));
                if (!isAutomaticRetry) {
                    Log.i(TAG, "Automatic retry on firmware upgrade failure is disabled.");
                }
            }

            Preference.putBoolean(context,
                    context.getResources().getString(R.string.firmware_upgrade_automatic_retry),
                    isAutomaticRetry);

            if (!upgradeData.isNull(context.getResources().getString(R.string.firmware_server))) {
                server = (String) upgradeData.get(context.getResources().getString(R.string.firmware_server));
                // When the server is empty, that means it is indicating to download from default server
                if (!server.isEmpty() && !Patterns.WEB_URL.matcher(server).matches()) {
                    String message = "Firmware upgrade URL provided is not valid.";
                    CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE,
                            Constants.Code.FAILURE, Constants.Status.MALFORMED_OTA_URL, message);
                    CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_FAILURE,
                            Preference.getInt(context, context.getResources().getString(R.string.operation_id)),
                            message);
                    Log.e(TAG, message);
                    return;
                } else {
                    Preference.putString(context, context.getResources().getString(R.string.firmware_server),
                            server);
                }
            }
        } catch (JSONException e) {
            Log.e(TAG, "Firmware upgrade payload parsing failed." + e);
            return;
        }
    }
    if (schedule != null && !schedule.trim().isEmpty()) {
        Log.i(TAG, "Upgrade scheduled received: " + schedule);
        Preference.putString(context, context.getResources().getString(R.string.alarm_schedule), schedule);
        try {
            AlarmUtils.setOneTimeAlarm(context, schedule, Constants.Operation.UPGRADE_FIRMWARE, null);
        } catch (ParseException e) {
            CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE,
                    Constants.Status.MALFORMED_REQUEST, e.getMessage());
        }
    } else {
        if (isStatusCheck) {
            Log.i(TAG, "Firmware status check is initiated by admin.");
        } else {
            Log.i(TAG, "Upgrade request initiated by admin.");

            String status = Preference.getString(context,
                    context.getResources().getString(R.string.upgrade_download_status));
            boolean isAutomaticUpgrade = Preference.getBoolean(context,
                    context.getResources().getString(R.string.firmware_upgrade_automatic_retry));

            if (Constants.Status.WIFI_OFF.equals(status) && isAutomaticUpgrade && !checkNetworkOnline()) {
                String msg = "Ignoring request as service waiting for WiFi to start upgrade.";
                Log.d(TAG, msg);
                CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.PENDING,
                        Constants.Status.OTA_UPGRADE_PENDING, msg);
                return;
            } else if (Constants.Status.OTA_UPGRADE_ONGOING.equals(status)) {
                String msg = "Checking for existing download. Will proceed this request if current download is no longer ongoing.";
                Log.d(TAG, msg);
                CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.PENDING,
                        Constants.Status.OTA_UPGRADE_ONGOING, msg);
                Preference.putString(context,
                        context.getResources().getString(R.string.upgrade_download_status),
                        Constants.Status.REQUEST_PLACED);
                Timer timeoutTimer = new Timer();
                timeoutTimer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        if (Constants.Status.REQUEST_PLACED.equals(Preference.getString(context,
                                context.getResources().getString(R.string.upgrade_download_status)))) {
                            Log.d(TAG,
                                    "Download is no longer ongoing. Proceeding download request from the agent.");
                            OTADownload otaDownload = new OTADownload(context);
                            otaDownload.startOTA();
                        } else {
                            String msg = "Request ignored because another download is ongoing.";
                            Log.d(TAG, msg);
                            CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE,
                                    Constants.Code.FAILURE, Constants.Status.OTA_UPGRADE_ONGOING, msg);
                        }
                    }
                }, Constants.FIRMWARE_UPGRADE_READ_TIMEOUT);
                return;
            }
        }

        //Prepare for upgrade
        OTADownload otaDownload = new OTADownload(context);
        otaDownload.startOTA();
    }
}