List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:com.cleanwiz.applock.service.AppUpdateService.java
public void checkVersion() { requestQueue = Volley.newRequestQueue(context); String url = "http://www.toolwiz.com/android/checkfiles.php"; final String oldVersionString = getApplicationVersion(); Uri.Builder builder = Uri.parse(url).buildUpon(); builder.appendQueryParameter("uid", AndroidUtil.getUdid(context)); builder.appendQueryParameter("version", oldVersionString); builder.appendQueryParameter("action", "checkfile"); builder.appendQueryParameter("app", "locklocker"); jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, builder.toString(), null, new Response.Listener<JSONObject>() { @Override//from ww w . java 2 s .c o m public void onResponse(JSONObject arg0) { // TODO Auto-generated method stub LogUtil.e("colin", "success"); if (arg0.has("status")) { try { String status = arg0.getString("status"); if (Integer.valueOf(status) == 1) { JSONObject msgJsonObject = arg0.getJSONObject("msg"); double version = msgJsonObject.getDouble("version"); if (Double.valueOf(oldVersionString) < version) { // ??? String intro = msgJsonObject.getString("intro"); AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle("?").setMessage(intro) .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ?? } }) .setNegativeButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.create().show(); } } else { LogUtil.e("colin", "check update status is error"); } } catch (JSONException e) { // TODO Auto-generated catch block LogUtil.e("colin", "JSONException" + e.getMessage()); e.printStackTrace(); } } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError arg0) { // TODO Auto-generated method stub } }); requestQueue.add(jsonObjectRequest); }
From source file:com.example.gps_project.Places.java
@Override public void onItemClick(AdapterView<?> arg0, View v, final int position, long arg3) { try {/*from ww w . jav a 2 s .c om*/ new AlertDialog.Builder(this).setTitle(R.string.check_in_title) .setMessage(String.format(getString(R.string.check_in_at), jsonArray.getJSONObject(position).getString("name"))) .setPositiveButton(R.string.checkin, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String placeID = ""; final JSONObject coordinate = new JSONObject(); try { placeID = jsonArray.getJSONObject(position).getString("id"); coordinate.put("latitude", jsonArray.getJSONObject(position) .getJSONObject("location").getString("lat")); coordinate.put("longitude", jsonArray.getJSONObject(position) .getJSONObject("location").getString("lon")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } params.putString("place", placeID); params.putString("accesstoken", Session.getActiveSession().getAccessToken()); params.putString("coordinates", coordinate.toString()); Intent myIntent = new Intent(getApplicationContext(), CheckinPage.class); myIntent.putExtras(params); startActivity(myIntent); } }).setNegativeButton(R.string.cancel, null).show(); } catch (JSONException e) { showToast("Error: " + e.getMessage()); } //} }
From source file:com.polyvi.xface.extension.advancedfiletransfer.XFileDownloader.java
@Override public void onSuccess() { mFileTransferRecorder.deleteDownloadInfo(mUrl); mFileTransferManager.removeFileTranferTask(mApp.getAppId(), mUrl); setState(INIT);/*from www . j ava2 s . c om*/ JSONObject jsonObj = new JSONObject(); try { jsonObj = XFileUtils.getEntry(mApp.getWorkSpace(), new File(mLocalFilePath)); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage()); } mCallbackCtx.success(jsonObj); }
From source file:com.polyvi.xface.extension.advancedfiletransfer.XFileDownloader.java
@Override public void onError(int errorCode) { setState(INIT);//from w w w.java2 s .co m String fullPath = null; String workspace = mApp.getWorkSpace(); if (mLocalFilePath.equals(workspace)) { fullPath = File.separator; } else { fullPath = mLocalFilePath.substring(workspace.length()); } JSONObject error = new JSONObject(); try { error.put("code", errorCode); error.put("source", mUrl); error.put("target", fullPath); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage()); } mCallbackCtx.error(error); }
From source file:com.polyvi.xface.extension.advancedfiletransfer.XFileDownloader.java
@Override public void onProgressUpdated(int completeSize, long totalSize) { mDownloadInfo.setCompleteSize(completeSize); JSONObject jsonObj = new JSONObject(); try {//from w w w. ja v a2 s . c om jsonObj.put("loaded", completeSize); jsonObj.put("total", mDownloadInfo.getTotalSize()); } catch (JSONException e) { XLog.e(CLASS_NAME, e.getMessage()); } XExtensionResult result = new XExtensionResult(XExtensionResult.Status.PROGRESS_CHANGING, jsonObj); result.setKeepCallback(true); mCallbackCtx.sendExtensionResult(result); }
From source file:org.steveleach.scoresheet.support.ScoresheetStore.java
public StoreResult save(ScoresheetModel model) { StoreResult result = null;/*from w ww .j av a 2s. c o m*/ String json = null; try { json = codec.toJson(model); } catch (JSONException e) { result = new StoreResult("Error building JSON : " + e.getMessage(), e); } if (json != null) { try { checkFileSystemStatus(); ensureBaseDirectoryExists(); File file = getMainFile(model); fileManager.writeTextFile(file, json); fileManager.copyFile(file, getLastFile(baseFileName)); result = new StoreResult("Saved " + baseFileName, true); } catch (IOException e) { result = new StoreResult("Error saving " + baseFileName + " : " + e.getMessage(), e); } } return result; }
From source file:com.chess.genesis.dialog.GameStatsDialog.java
public GameStatsDialog(final Context context, final JSONObject json) { super(context, BaseDialog.CANCEL); String[] statusArr = null;/*from w w w .j ava 2 s.co m*/ String gametype = null, gameid = null, sign = null; int eventtype = 0, ycol = 0, w_from = 0, w_to = 0, b_from = 0, b_to = 0; try { gameid = json.getString("gameid"); ycol = json.getInt("yourcolor"); statusArr = STATUS_MAP.get(json.getInt("status") * ycol); gametype = json.getString("gametype"); gametype = gametype.substring(0, 1).toUpperCase(Locale.US) + gametype.substring(1); eventtype = Integer.parseInt(json.getString("eventtype")); if (ycol == Piece.WHITE) opponent = json.getString("black_name"); else opponent = json.getString("white_name"); if (eventtype != Enums.INVITE) { w_from = json.getJSONObject("white").getInt("from"); w_to = json.getJSONObject("white").getInt("to"); b_from = json.getJSONObject("black").getInt("from"); b_to = json.getJSONObject("black").getInt("to"); } } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } final int to = (ycol == Piece.WHITE) ? w_to : b_to; diff = (ycol == Piece.WHITE) ? (w_to - w_from) : (b_to - b_from); sign = (diff >= 0) ? "+" : "-"; title = statusArr[0]; result = statusArr[1]; psr_type = gametype + " PSR :"; if (eventtype == Enums.INVITE) psr_score = "None (Invite Game)"; else psr_score = sign + String.valueOf(Math.abs(diff)) + " (" + String.valueOf(to) + ')'; final GameDataDB db = new GameDataDB(context); db.archiveNetworkGame(gameid, w_from, w_to, b_from, b_to); db.close(); }
From source file:net.chunkyhosting.Roe.computer.CHGManager.gui.dialogs.DownloadNotice.java
public void startDownload() { this.addTextToPanel("<p>Starting download of " + this.getDownloads().size() + " files.</p>"); Iterator<Map.Entry<JSONObject, URL>> it = this.getDownloads().entrySet().iterator(); int x = 0;/* w w w . j a v a 2 s. c om*/ while (it.hasNext()) { x += 1; Map.Entry<JSONObject, URL> download = it.next(); JSONObject jsonObject = (JSONObject) download.getKey(); System.out.println("Download: " + download.getValue().toString() + ", " + download.getKey().toString()); this.addTextToPanel("<p>Starting download of " + jsonObject.getString("Folder") + File.separator + jsonObject.getString("FileName") + "." + jsonObject.getString("Extension") + " located at: " + download.getValue() + "</p>"); File file = new File(CHGManager.getInstance().getSettings().getWorkingDirectory() + File.separator + jsonObject.getString("Folder")); file.mkdirs(); file = new File(CHGManager.getInstance().getSettings().getWorkingDirectory() + File.separator + jsonObject.getString("Folder") + File.separator + jsonObject.getString("FileName") + "." + jsonObject.getString("Extension")); try { CHGManager.getInstance().getNetwork().downloadFile(download.getValue(), file); } catch (JSONException e) { this.addTextToPanel("<p>ERROR(" + e.getMessage() + ") An error occoured while downloading: " + jsonObject.getString("Folder") + File.separator + jsonObject.getString("FileName") + "." + jsonObject.getString("Extension") + " located at: " + download.getValue() + ". Please report to the developers!</p>"); } this.addTextToPanel("<p>Download of " + jsonObject.getString("Folder") + File.separator + jsonObject.getString("FileName") + "." + jsonObject.getString("Extension") + " located at: " + download.getValue() + ". Has finished! We have " + (this.getDownloads().size() - x) + " files to go!</p>"); } }
From source file:org.loklak.android.client.PushClient.java
/** * transmit the timeline to several hosts * @param timeline//from w ww .j a va 2s . c o m * @return the json object from the host api if the transfer was successfull or null otherwise */ public static JSONObject push(String hoststub, Timeline timeline) { // transmit the timeline try { if (hoststub.endsWith("/")) hoststub = hoststub.substring(0, hoststub.length() - 1); JSONObject json = JsonIO.pushJson(hoststub + "/api/push.json", "data", timeline.toJSON(false)); if (json != null) return json; } catch (JSONException e) { Log.d("PushClient", e.getMessage(), e); return null; } return null; }
From source file:org.kei.android.phone.mangastore.AppFragment.java
private void convertFromJSON(JSONArray response) { boolean aborted = true; boolean finished = true; boolean inprogress = true; final int position = CFG.get(Config.KEY_PAGER_CURRENT_TAB, 0); final MangaType selectedType = MangaType.getType(position); if (position == MangaStorePagerActivity.POSITION_MANGAS) { aborted = CFG.get(Config.KEY_SHOW_MANGAS_ABORTED, true); finished = CFG.get(Config.KEY_SHOW_MANGAS_FINISHED, true); inprogress = CFG.get(Config.KEY_SHOW_MANGAS_INPROGRESS, true); } else if (position == MangaStorePagerActivity.POSITION_ANIMES) { aborted = CFG.get(Config.KEY_SHOW_ANIMES_ABORTED, true); finished = CFG.get(Config.KEY_SHOW_ANIMES_FINISHED, true); inprogress = CFG.get(Config.KEY_SHOW_ANIMES_INPROGRESS, true); } else if (position == MangaStorePagerActivity.POSITION_MOVIES) { aborted = CFG.get(Config.KEY_SHOW_MOVIES_ABORTED, true); finished = CFG.get(Config.KEY_SHOW_MOVIES_FINISHED, true); inprogress = CFG.get(Config.KEY_SHOW_MOVIES_INPROGRESS, true); } else if (position == MangaStorePagerActivity.POSITION_OAV) { aborted = CFG.get(Config.KEY_SHOW_OAV_ABORTED, true); finished = CFG.get(Config.KEY_SHOW_OAV_FINISHED, true); inprogress = CFG.get(Config.KEY_SHOW_OAV_INPROGRESS, true); }/* w w w .ja va2 s . c om*/ if (response.length() > 0) { List<MangaModel> mangaList = new ArrayList<MangaModel>(); // looping through json and adding to movies list for (int i = 0; i < response.length(); i++) { try { JSONObject mObj = response.getJSONObject(i); MangaType type = MangaType.getType(mObj.getInt("type")); StatusType status = StatusType.getType(mObj.getInt("status")); if (type != selectedType) continue; if (!aborted && status == StatusType.ABORTED) continue; if (!finished && status == StatusType.FINISHED) continue; if (!inprogress && status == StatusType.INPROGRESS) continue; int id = mObj.getInt("id"); int year = mObj.getInt("year"); String label = mObj.getString("name"); int volume = mObj.getInt("number"); MangaModel m = new MangaModel(id, type, label, year, volume, status); mangaList.add(0, m); } catch (JSONException e) { Tools.toast(getActivity(), R.drawable.ic_launcher, "JSON Parsing error: " + e.getMessage()); e.printStackTrace(); mangaList.clear(); break; } } if (!mangaList.isEmpty()) { adapter.clear(); adapter.addAll(mangaList); adapter.sort(); if (isAdded()) indexer.forceReload(); else refresh(); } } // stopping swipe refresh swipeRefreshLayout.setRefreshing(false); }