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.example.android.popularmoviesist2.data.FetchMovieTask.java

@Override
protected String[] doInBackground(String... params) {

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;
    orderBy = params[0];//  www .  j a  va2 s . c o m

    String moviesJsonStr = null;

    try {

        final String MOVIE_BASE_URL = "http://api.themoviedb.org/3/movie/" + orderBy;
        final String APIKEY_PARAM = "api_key";

        Uri builtUri = Uri.parse(MOVIE_BASE_URL).buildUpon()
                .appendQueryParameter(APIKEY_PARAM, BuildConfig.OPEN_TMDB_MAP_API_KEY).build();

        URL url = new URL(builtUri.toString());

        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        InputStream inputStream = urlConnection.getInputStream();
        StringBuffer buffer = new StringBuffer();
        if (inputStream == null) {
            return null;
        }
        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {
            buffer.append(line + "\n");
        }

        if (buffer.length() == 0) {
            return null;
        }
        moviesJsonStr = buffer.toString();

        Log.d(LOG_TAG, "Buffer " + moviesJsonStr);

        getMoviesDataFromJson(moviesJsonStr);

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error ", e);
        return null;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                Log.e(LOG_TAG, "Error closing stream", e);
            }
        }
    }

    return null;
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public DataServerInfoObject(String jsonString) {
    try {/* w ww .j a  va 2  s  .c o  m*/
        this.jsonObject = new JSONObject(jsonString);
    } catch (JSONException e) {
        System.out.println(errorPrefix + e.getMessage());
    }
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public String get(String key) {
    String object = null;/*  w ww.  ja  v a  2 s . c om*/

    try {
        object = this.jsonObject.getString(key);
    } catch (JSONException e) {
        System.out.println(errorPrefix + e.getMessage());
    }

    return object;
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public void putArrayWithEscaping(String key, Collection objectArray) {
    JSONArray jsonArray = new JSONArray(objectArray);

    try {/* w ww . ja v  a2s .co  m*/
        this.jsonObject.put(key, jsonArray);
    } catch (JSONException e) {
        System.out.println(errorPrefix + e.getMessage());
    }
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public void putArrayWithoutEscaping(String key, Collection objectArray) {
    JSONArray jsonArray = new JSONArray();

    try {//w w w  .  j a  v a  2 s  . co m
        for (Object object : objectArray) {
            JSONObject jsonObject = new JSONObject(object.toString());
            jsonArray.put(jsonObject);
        }

        this.jsonObject.put(key, jsonArray);
    } catch (JSONException e) {
        System.out.println(errorPrefix + e.getMessage());
    }
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public void putDataInObject(JSONObject jsonObject, String key, String stringData) {
    if (jsonObject != null) {

        try {/*from   w ww .ja va  2 s. c  o m*/
            jsonObject.put(key, stringData);
        } catch (JSONException e) {
            System.out.println(errorPrefix + e.getMessage());
        }
    }
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public void putDataInObject(JSONObject jsonObject, String key, int intData) {
    if (jsonObject != null) {

        try {//from   www.j av  a2s  .  co m
            jsonObject.put(key, intData);
        } catch (JSONException e) {
            System.out.println(errorPrefix + e.getMessage());
        }
    }
}

From source file:org.jaibo.api.dataserver.DataServerInfoObject.java

public void putDataInObject(JSONObject jsonObject, String key, boolean booleanData) {
    if (jsonObject != null) {

        try {//from www .ja  va 2s .  c  o  m
            jsonObject.put(key, booleanData);
        } catch (JSONException e) {
            System.out.println(errorPrefix + e.getMessage());
        }
    }
}

From source file:com.chess.genesis.net.GenesisNotifier.java

private void NewMove(final JSONObject json) {
    try {/*from   w w  w  .j av  a2  s  .com*/
        final JSONArray ids = json.getJSONArray("gameids");

        for (int i = 0, len = ids.length(); i < len; i++) {
            if (error)
                return;
            net.game_status(ids.getString(i));
            net.run();

            lock++;
        }
        // Save sync time
        final PrefEdit pref = new PrefEdit(this);
        pref.putLong(R.array.pf_lastgamesync, json.getLong("time"));
        pref.commit();
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.chess.genesis.net.GenesisNotifier.java

private void NewMsgs(final JSONObject json) {
    try {/*w  ww  .j  a  va  2  s  .  c  o m*/
        final JSONArray msgs = json.getJSONArray("msglist");
        final long time = json.getLong("time");

        for (int i = 0, len = msgs.length(); i < len; i++) {
            final JSONObject item = msgs.getJSONObject(i);
            db.insertMsg(item);
        }

        // Save sync time
        final PrefEdit pref = new PrefEdit(this);
        pref.putLong(R.array.pf_lastmsgsync, time);
        pref.commit();
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}