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:reseau.jeu.serveur.Protocole.java

/**
 * Permet de construire le message de suppression d'une crature
 * //from   w  w  w . j a v a2 s  . c o m
 * @param creature la creature
 * @return Une structure JSONObject
 */
public static String construireMsgCreatureSuppression(Creature creature, Joueur joueur) {
    JSONObject msg = new JSONObject();

    try {
        msg.put("TYPE", CREATURE_SUPPRESSION);
        msg.put("ID_CREATURE", creature.getId());
        msg.put("ID_TUEUR", joueur.getId());

    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgChat(String message, int cible) {
    JSONObject msg = new JSONObject();

    try {/* ww w  . java  2s .  c  o  m*/
        msg.put("TYPE", JOUEUR_MESSAGE);
        msg.put("CIBLE", cible);
        msg.put("MESSAGE", message);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgChangerEquipe(int etat) {
    JSONObject msg = new JSONObject();

    try {/*w w  w.ja va2  s  . c om*/
        msg.put("TYPE", JOUEUR_CHANGER_EQUIPE);
        msg.put("STATUS", etat);
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgCreatureArrivee(Creature creature) {
    JSONObject msg = new JSONObject();

    try {//from   w w w .ja  v  a  2s. co m
        msg.put("TYPE", CREATURE_ARRIVEE);
        msg.put("ID_CREATURE", creature.getId());
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgMessage(int idAuteur, String contenu) {
    JSONObject msg = new JSONObject();

    try {//w w w .  j a va  2 s  .  com
        // Construction de la structure JSON
        msg.put("TYPE", JOUEUR_MESSAGE);
        msg.put("ID_JOUEUR", idAuteur);
        msg.put("MESSAGE", contenu);
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgJoueurDeconnecte(int idJoueur) {
    JSONObject msg = new JSONObject();

    try {/* w w  w  . j  a va  2 s. c o m*/
        // Construction de la structure JSON
        msg.put("TYPE", JOUEUR_DECONNEXION);
        msg.put("ID_JOUEUR", idJoueur);
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:reseau.jeu.serveur.Protocole.java

public static String construireMsgEquipeAPerdue(int id) {
    JSONObject msg = new JSONObject();

    try {/*from   w  ww  .j a v a  2 s . com*/
        // Construction de la structure JSON
        msg.put("TYPE", EQUIPE_A_PERDUE);
        msg.put("ID_EQUIPE", id);
    } catch (JSONException jsone) {
        jsone.printStackTrace();
    }

    return msg.toString();
}

From source file:org.cgiar.ilri.odk.pull.backend.services.FetchFormDataService.java

/**
 * This method is called whenever the service is called. Note that the service might have
 * already been running when it was called
 *
 * @param intent The intent used to call the service
 *///from  w  w w  .j a  v  a2  s.co  m
@Override
protected void onHandleIntent(Intent intent) {
    formName = intent.getStringExtra(KEY_FORM_NAME);
    if (formName != null) {
        //fetch data on the form
        try {
            String jsonString = DataHandler.sendDataToServer(this, null,
                    DataHandler.URI_FETCH_FORM_DATA + URLEncoder.encode(formName, "UTF-8"));
            if (jsonString != null) {
                try {
                    JSONObject jsonObject = new JSONObject(jsonString);
                    JSONObject fileData = jsonObject.getJSONObject("files");
                    Iterator<String> keys = fileData.keys();
                    String fetchedFilesString = "";
                    while (keys.hasNext()) {
                        String currFileName = keys.next();
                        Log.d(TAG, "Processing " + currFileName);
                        JSONArray currFileData = fileData.getJSONArray(currFileName);
                        if (currFileName.equals(Form.DEFAULT_CSV_FILE_NAME)) {
                            Log.d(TAG, "Treating " + currFileName + " like a itemset file");
                            Log.d(TAG, currFileName + " data = " + currFileData.toString());
                            String csv = getCSVString(currFileData);
                            if (csv != null) {
                                saveCSVInFile(currFileName + Form.SUFFIX_CSV, csv);
                                fetchedFilesString = fetchedFilesString + "\n" + " - " + currFileName
                                        + Form.SUFFIX_CSV;
                            } else {
                                Log.w(TAG, Form.DEFAULT_CSV_FILE_NAME
                                        + " from the server is null. Unable to save this on the device");
                                Toast.makeText(FetchFormDataService.this,
                                        getResources().getText(R.string.unable_fetch_data_for) + " "
                                                + currFileName,
                                        Toast.LENGTH_LONG).show();

                            }
                        } else {
                            Log.d(TAG, "Treating " + currFileName + " like an external data file");
                            boolean dataDumped = saveDataInDb(currFileName, currFileData);
                            String csv = getCSVString(currFileData);
                            if (csv != null) {
                                if (dataDumped) {
                                    saveCSVInFile(currFileName + Form.SUFFIX_CSV + Form.SUFFIX_IMPORTED, csv);
                                    fetchedFilesString = fetchedFilesString + "\n" + " - " + currFileName
                                            + Form.SUFFIX_DB;
                                    fetchedFilesString = fetchedFilesString + "\n" + " - " + currFileName
                                            + Form.SUFFIX_CSV + Form.SUFFIX_IMPORTED;
                                } else {
                                    saveCSVInFile(currFileName + Form.SUFFIX_CSV, csv);
                                    fetchedFilesString = fetchedFilesString + "\n" + " - " + currFileName
                                            + Form.SUFFIX_CSV;
                                }
                            } else {
                                Log.w(TAG, currFileName
                                        + " from the server is null. Unable to save this on the device");
                                Toast.makeText(FetchFormDataService.this,
                                        getResources().getText(R.string.unable_fetch_data_for) + " "
                                                + currFileName,
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    }
                    DataHandler.updateFormLastUpdateTime(FetchFormDataService.this, formName);
                    if (fetchedFilesString.length() > 0) {//only show the notification if at least one file updated
                        updateNotification(formName, getString(R.string.fetched_data),
                                getString(R.string.the_following_files_were_added) + fetchedFilesString);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e(TAG,
                        "Data from server null. Something happened while trying to fetch csv for " + formName);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    } else {
        Log.w(TAG, "Form name from intent bundle was null, doing nothing");
    }
}

From source file:org.cgiar.ilri.odk.pull.backend.services.FetchFormDataService.java

/**
 * Creates a CSV string corresponding to the provided JSONArray. Indexes in JSONArray expected
 * to correspond to rows in the CSV string. Each JSONArray element should be a JSONObject with
 * children being column values (with keys being column names). Make sure all JSONObjects in the
 * JSONArray have the same number of key-value pairs.
 *
 * @param jsonArray JSONArray with the data
 * @return  The CSV string or NULL if the JSONArray is empty or if an error occurs
 *//* w ww.  ja  va  2s  .  c  o m*/
private String getCSVString(JSONArray jsonArray) {
    String csv = null;
    if (jsonArray.length() > 0) {
        try {
            csv = "";
            List<String> keys = new ArrayList<String>();
            Iterator<String> iterator = jsonArray.getJSONObject(0).keys();
            while (iterator.hasNext()) {
                String currKey = iterator.next();
                keys.add(currKey);
                if (csv.length() == 0) {
                    csv = currKey;
                } else {
                    csv = csv + "," + currKey;
                }
            }
            csv = csv + "\n";
            for (int rowIndex = 0; rowIndex < jsonArray.length(); rowIndex++) {
                JSONObject currRow = jsonArray.getJSONObject(rowIndex);
                for (int keyIndex = 0; keyIndex < keys.size(); keyIndex++) {
                    String currValue = currRow.getString(keys.get(keyIndex));
                    if (currValue != null) {
                        csv = csv + currValue;
                    }
                    if (keyIndex < keys.size() - 1) {//not the last item in row
                        csv = csv + ",";
                    }
                }
                csv = csv + "\n";//will potentially lead to having an empty last line in the csv
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        Log.w(TAG, "Provided jsonArray to be converted to CSV is empty returning null as csv");
    }
    return csv;
}

From source file:com.aniruddhc.acemusic.player.GMusicHelpers.WebClientPlaylistsSchema.java

@Override
public ArrayList<WebClientSongsSchema> fromJsonArray(JSONArray jsonArray) {

    ArrayList<WebClientSongsSchema> songList = new ArrayList<WebClientSongsSchema>();
    if (jsonArray != null && jsonArray.length() > 0) {
        for (int i = 0; i < jsonArray.length(); i++) {
            try {
                WebClientSongsSchema song = new WebClientSongsSchema()
                        .fromJsonObject(jsonArray.getJSONObject(i));
                songList.add(song);/*from w ww .j  av  a2s  .c  o  m*/

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

    }
    return songList;
}