Example usage for org.json JSONException toString

List of usage examples for org.json JSONException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.mobiperf_library.util.MeasurementJsonConvertor.java

public static MeasurementTask makeMeasurementTaskFromJson(JSONObject json) throws IllegalArgumentException {
    try {//w  w w  .j  a v a 2s .c  om
        String type = String.valueOf(json.getString("type"));
        Class taskClass = MeasurementTask.getTaskClassForMeasurement(type);
        Method getDescMethod = taskClass.getMethod("getDescClass");
        // The getDescClassForMeasurement() is static and takes no arguments
        Class descClass = (Class) getDescMethod.invoke(null, (Object[]) null);
        MeasurementDesc measurementDesc = (MeasurementDesc) gson.fromJson(json.toString(), descClass);

        Object cstParam = measurementDesc;
        Constructor<MeasurementTask> constructor = taskClass.getConstructor(MeasurementDesc.class);
        return constructor.newInstance(cstParam);
    } catch (JSONException e) {
        throw new IllegalArgumentException(e);
    } catch (SecurityException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (NoSuchMethodException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (IllegalArgumentException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (InstantiationException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
        Logger.w(e.getMessage());
        throw new IllegalArgumentException(e);
    } catch (InvocationTargetException e) {
        Logger.w(e.toString());
        throw new IllegalArgumentException(e);
    }
}

From source file:com.krayzk9s.imgurholo.ui.CommentsFragment.java

private void addComments(JSONObject comments) {
    try {/* w w w.  ja  va2s  . c  om*/
        commentDataArray = new ArrayList<JSONParcelable>();
        JSONArray data = comments.getJSONArray("data");
        for (int i = 0; i < data.length(); i++) {
            JSONObject message = data.getJSONObject(i);
            JSONParcelable dataParcel = new JSONParcelable();
            dataParcel.setJSONObject(message);
            commentDataArray.add(dataParcel);
        }
        commentsAdapter.addAll(commentDataArray);
    } catch (JSONException e) {
        errorText.setVisibility(View.VISIBLE);
        errorText.setText("Error getting comments");
        Log.e("Error!", "adding messages" + e.toString());
    }
    mDrawerList.setAdapter(commentsAdapter);
    commentsAdapter.notifyDataSetChanged();
}

From source file:com.t2.compassionMeditation.DeviceManagerActivity.java

/**
 * Receives a json string containing data about all of the paired sensors
 * the adds a new BioSensor for each one to the mBioSensors collection
 * //from  w w w.jav a  2s. c  o  m
 * @param jsonString String containing info on all paired devices
 */
private void populateBioSensors(String jsonString) {

    Log.d(TAG, this.getClass().getSimpleName() + " populateBioSensors");

    // Now clear it out and Re-populate it.
    mBioSensors.clear();
    try {
        JSONArray jsonArray = new JSONArray(jsonString);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Boolean enabled = jsonObject.getBoolean("enabled");
            String name = jsonObject.getString("name");
            String address = jsonObject.getString("address");
            int connectionStatus = jsonObject.getInt("connectionStatus");

            if (name.equalsIgnoreCase("system")) {
                mBluetoothEnabled = enabled;
            } else {
                Log.i(TAG, "Adding sensor " + name + ", " + address + (enabled ? ", enabled" : ", disabled")
                        + " : " + Util.connectionStatusToString(connectionStatus));
                Log.i(TAG, this.getClass().getSimpleName() + " Adding sensor " + name + ", " + address
                        + (enabled ? ", enabled" : ", disabled"));
                BioSensor bioSensor = new BioSensor(name, address, enabled);

                bioSensor.mConnectionStatus = connectionStatus;
                mBioSensors.add(bioSensor);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to map of dictionary references.
 * //  w  w w.j a va 2 s . c  o m
 * @param jsonString - JSON string to be parsed
 */
public void parseDicRef(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    Map<String, String> dicRefTemp = new HashMap<>();
    JSONObject dicRefJson;
    try {
        dicRefJson = new JSONObject(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "getting parseJapaneseKeb()  initial expression failed: " + e.toString());
        return;
    }

    Iterator<?> keys = dicRefJson.keys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value;
        try {
            value = dicRefJson.getString(key);
            if (key != null && value != null) {
                dicRefTemp.put(key, value);
            }
        } catch (JSONException e) {
            Log.w(LOG_TAG, "parsing dicRef failed");
        }
    }
    if (dicRefTemp.size() > 0) {
        for (String key : dicRefTemp.keySet()) {
            addDicRef(key, dicRefTemp.get(key));
        }
    }

}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of Onyomi.
 * /*w  w  w . ja v a  2s .  co  m*/
 * @param jsonString - JSON string to be parsed
 */
public void parseRmGroupJaOn(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseRmGroupJaOn() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addRmGroupJaOn(str);
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of Kunyomi.
 * //from   ww w. j  av  a2  s.c  om
 * @param jsonString - JSON string to be parsed
 */
public void parseRmGroupJaKun(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseRmGroupJaKun() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addRmGroupJaKun(str);
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of english meanings.
 * //from  w ww  .j a  v  a  2s.com
 * @param jsonString - JSON string to be parsed
 */
public void parseMeaningEnglish(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseMeaningEnglish() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addMeaningEnglish(str);
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of french meanings.
 * //from   w  w  w  .  j  a v  a2  s.  c om
 * @param jsonString - JSON string to be parsed
 */
public void parseMeaningFrench(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseMeaningFrench() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addMeaningFrench(str);
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of dutch meanings.
 * //from w ww.j  a v  a 2s  . c om
 * @param jsonString - JSON string to be parsed
 */
public void parseMeaningDutch(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseMeaningDutch() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addMeaningDutch(str);
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java

/**
 * Takes json string and parses it to list of german meanings.
 * /*  w w w .ja va2 s.c om*/
 * @param jsonString - JSON string to be parsed
 */
public void parseMeaningGerman(String jsonString) {
    if (jsonString == null || jsonString.length() < 1) {
        return;
    }
    List<String> temp;
    JSONArray parseJSON;
    try {
        parseJSON = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "parsing parseMeaningGerman() - initial expression failed: " + e.toString());
        return;
    }
    temp = this.parseOneJSONArray(parseJSON);
    for (String str : temp) {
        this.addMeaningGerman(str);
    }
}