List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:org.adblockplus.android.AdblockPlus.java
/** * Adds provided subscription and removes previous subscriptions if any. * /*www.j a va 2 s.co m*/ * @param subscription * Subscription to add */ public void setSubscription(Subscription subscription) { if (subscription != null) { final JSONObject jsonSub = new JSONObject(); try { jsonSub.put("url", subscription.url); jsonSub.put("title", subscription.title); jsonSub.put("homepage", subscription.homepage); js.execute(new Runnable() { @Override public void run() { js.evaluate("clearSubscriptions()"); js.evaluate("addSubscription(\"" + StringEscapeUtils.escapeJavaScript(jsonSub.toString()) + "\")"); } }); } catch (JSONException e) { // TODO Auto-generated catch block Log.e(TAG, e.getMessage(), e); } } }
From source file:com.rxsampleapp.RxApiTestActivity.java
public void createAnUserJSONObject(View view) { JSONObject jsonObject = new JSONObject(); try {// w w w. j a v a2 s . c o m jsonObject.put("firstname", "Rohit"); jsonObject.put("lastname", "Kumar"); } catch (JSONException e) { e.printStackTrace(); } RxAndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER) .addJSONObjectBody(jsonObject).build().setAnalyticsListener(new AnalyticsListener() { @Override public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<JSONObject>() { @Override public void onCompleted() { Log.d(TAG, "onComplete Detail : createAnUserJSONObject completed"); } @Override public void onError(Throwable e) { if (e instanceof ANError) { ANError anError = (ANError) e; if (anError.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + anError.getErrorCode()); Log.d(TAG, "onError errorBody : " + anError.getErrorBody()); Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } } else { Log.d(TAG, "onError errorMessage : " + e.getMessage()); } } @Override public void onNext(JSONObject response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } }); }
From source file:com.fortydegree.ra.data.POIDownloader.java
public void download(Location l, int radius, int maxResults, final CallBack<List<Marker>> places) throws WebServiceException { List<String> parameters = Arrays.asList("latitude", Double.toString(l.getLatitude()), "longitude", Double.toString(l.getLongitude()), "radius", Integer.toString(radius), "max", Integer.toString(maxResults)); this.downloader.download(parameters, new CallBack<String>() { public void execute(String input) { try { if (input != null && input.length() > 0) { List<Marker> list = JsonUnmarshaller.load(new JSONObject(input)); places.execute(list); }//w w w .j a v a2 s.c o m } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); throw new Error(e);// should not happen } } }, new CallBack<Throwable>() { public void execute(Throwable input) { Log.e(TAG, input.getMessage(), input); } }); }
From source file:com.github.dfa.diaspora_android.data.PodUserProfile.java
public boolean parseJson(String jsonStr) { try {/*from w w w. j a va 2s . c o m*/ json = new JSONObject(jsonStr); lastLoaded = System.currentTimeMillis(); // Avatar if (json.has("avatar")) { JSONObject avatarJson = json.getJSONObject("avatar"); if (avatarJson.has("large") && setAvatarUrl(avatarJson.getString("large"))) { app.getAvatarImageLoader().clearAvatarImage(); appSettings.setAvatarUrl(avatarUrl); } } // GUID (User id) if (json.has("guid") && loadGuid(json.getString("guid"))) { appSettings.setProfileId(guid); } // Name if (json.has("name") && loadName(json.getString("name"))) { appSettings.setName(name); } // Unread message count if (json.has("notifications_count") && loadNotificationCount(json.getInt("notifications_count"))) { appSettings.setNotificationCount(notificationCount); } // Unread message count if (json.has("unread_messages_count") && loadUnreadMessagesCount(json.getInt("unread_messages_count"))) { appSettings.setUnreadMessageCount(unreadMessagesCount); } // Aspect if (json.has("aspects") && loadAspects(json.getJSONArray("aspects"))) { appSettings.setPodAspects(podAspects); } // Followed tags if (json.has("android_app.followed_tags") && loadFollowedTags(json.getJSONArray("android_app.followed_tags"))) { appSettings.setFollowedTags(followedTags); } isWebUserProfileLoaded = true; } catch (JSONException e) { AppLog.d(this, e.getMessage()); isWebUserProfileLoaded = false; } lastLoaded = System.currentTimeMillis(); return isWebUserProfileLoaded; }
From source file:com.prey.json.actions.Geofencing.java
public void start(Context ctx, List<ActionResult> lista, JSONObject parameters) { try {/*from w w w.ja v a 2 s.c o m*/ String origin = parameters.getString("origin"); String[] centralPoints = origin.split(","); String longitude = centralPoints[0]; String latitude = centralPoints[1]; String radius = parameters.getString("radius"); Bundle bundle = new Bundle(); bundle.putDouble("longitude", Double.parseDouble(longitude)); bundle.putDouble("latitude", Double.parseDouble(latitude)); bundle.putFloat("radius", Float.parseFloat(radius)); bundle.putInt("type", ProxAlertActivity.START); Intent popup = new Intent(ctx, ProxAlertActivity.class); popup.putExtras(bundle); popup.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(popup); PreyLogger.i("Finish Geofencing start"); } catch (JSONException e) { PreyLogger.e("Error en json:" + e.getMessage(), e); PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx, UtilJson.makeMapParam("start", "geofence", "failed", e.getMessage())); } }
From source file:com.odoo.core.rpc.wrapper.OdooWrapper.java
private void newJSONPOSTRequest(final String url, JSONObject params, IOdooResponse odooResponse, OdooSyncResponse backResponse) { OdooLog.d("REQUEST URL : " + url); final JSONObject postData = createRequestWrapper(params, odooResponse); OdooLog.d("POST DATA: " + postData); RequestFuture<JSONObject> requestFuture = RequestFuture.newFuture(); if (backResponse == null) { Response.ErrorListener errorListener = new Response.ErrorListener() { @Override/*from w w w . j ava 2s .co m*/ public void onErrorResponse(VolleyError error) { OdooLog.d("ERROR RESPONSE : " + error.getMessage()); String message = error.getMessage(); int responseCode = -1; if (error.networkResponse != null) { message = "Server Error :" + error.networkResponse.statusCode; switch (error.networkResponse.statusCode) { case 400: responseCode = Odoo.ErrorCode.OdooServerError.get(); break; case 404: responseCode = Odoo.ErrorCode.InvalidURL.get(); break; default: responseCode = Odoo.ErrorCode.UnknownError.get(); } } OdooError odooError = new OdooError(message, error); odooError.setResponseCode(responseCode); if (error instanceof TimeoutError) { odooError.setMessage("Request Time out"); odooError.setServerTrace("Requested too many records. \n\n" + "You can update values before requesting data:\n" + "Odoo.REQUEST_TIMEOUT_MS\n" + "Odoo.DEFAULT_MAX_RETRIES"); } try { IOdooResponse response = responseQueue.get(postData.getInt("id")); if (response != null) { response.onError(odooError); responseQueue.remove(postData.getInt("id")); } } catch (JSONException e) { OdooLog.e(e, e.getMessage()); } } }; JsonObjectRequest request = new JsonObjectRequest(url, postData, OdooWrapper.this, errorListener); request.setRetryPolicy(new DefaultRetryPolicy(new_request_timeout, new_request_max_retry, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(request); } else { JsonObjectRequest request = new JsonObjectRequest(url, postData, requestFuture, requestFuture); request.setRetryPolicy(new DefaultRetryPolicy(new_request_timeout, new_request_max_retry, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(request); try { backResponse.setResponse(parseToResponse(requestFuture.get())); } catch (Exception e) { OdooLog.e(e); } } new_request_timeout = Odoo.REQUEST_TIMEOUT_MS; new_request_max_retry = Odoo.DEFAULT_MAX_RETRIES; }
From source file:com.odoo.core.rpc.wrapper.OdooWrapper.java
private void permRead(String model, List<Integer> ids, IOdooResponse callback, OdooSyncResponse backResponse) { try {//from w ww. jav a2 s.co m OArguments args = new OArguments(); args.add(new JSONArray(ids.toString())); callMethod(model, "perm_read", args, null, null, callback, backResponse); } catch (JSONException e) { OdooLog.e(e, e.getMessage()); } }
From source file:com.dedipower.portal.android.ManagedServerLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.managedserverlanding); //temp/*from w ww. j ava 2s . co m*/ list = (ListView) findViewById(R.id.ManagedServerList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); ManagedServerAdaptor adapter = new ManagedServerAdaptor(ManagedServerLanding.this, listOfManagedServers, API.SessionID); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { int ServerCount = 0; public void run() { try { Servers = API.PortalQuery("servers", "none"); Success = Servers.getString("success"); } catch (JSONException e) { //UpdateErrorMessage("An unrecoverable JSON Exception occured."); ErrorMessage = "An unrecoverable JSON Exception occured."; } if (Success.equals("false")) { try { //UpdateErrorMessage(Servers.getString("msg")); ErrorMessage = Servers.getString("msg"); } catch (JSONException e) { //UpdateErrorMessage("An unrecoverable JSON Exception occured."); ErrorMessage = "An unrecoverable JSON Exception occured."; } } else { Log.i("APIFuncs", Servers.toString()); try { ManagedServers = Servers.getJSONArray("servers"); //UpdateErrorMessage(""); ErrorMessage = ""; } catch (JSONException e) { //UpdateErrorMessage("There are no Managed servers in your account."); ErrorMessage = "There are no Managed servers in your account."; } try { ServerCount = ManagedServers.length(); } catch (Exception e) { ServerCount = 0; } if (ServerCount == 0) { ErrorMessage = "There are no Managed servers for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ServerCount; i++) { try { CurrentServer = ManagedServers.getJSONObject(i).getJSONObject("Server"); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } //Log.e("APIFuncs",CurrentServer.toString(3)); listOfManagedServers.add(new ManagedServer(GetString("ip"), GetString("servercode"), GetString("description"), GetString("facility"), GetInt("bandwidth"), GetString("bandwidthTotal"), GetBool("monitored"), GetInt("transferlimit"), GetString("software"), GetString("state"), GetBool("managedbackupenabled"))); } } handler.sendEmptyMessage(0); } }; dataPreload.start(); //temp /*try { Servers = API.PortalQuery("servers", "none"); Success = Servers.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } if(Success == "false") { try { UpdateErrorMessage(Servers.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs",Servers.toString()); try { ManagedServers = Servers.getJSONArray("servers"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no Managed servers in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.ManagedServerList); List<ManagedServer> listOfManagedServers = new ArrayList<ManagedServer>(); int ServerCount = ManagedServers.length(); for(int i = 0; i < ServerCount; i++) { try { CurrentServer = ManagedServers.getJSONObject(i).getJSONObject("Server"); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } //Log.e("APIFuncs",CurrentServer.toString(3)); listOfManagedServers.add(new ManagedServer(GetString("ip"), GetString("servercode"), GetString("description"), GetString("facility"), GetInt("bandwidth"), GetString("bandwidthTotal"), GetBool("monitored"), GetInt("transferlimit"), GetString("software"), GetString("state"), GetBool("managedbackupenabled"))); } ManagedServerAdaptor adapter = new ManagedServerAdaptor(this, listOfManagedServers, API.SessionID); list.setAdapter(adapter); }*/ }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
private static JSONObject cursorToDict(String tableName, Cursor c) { int totalColumn = c.getColumnCount(); JSONObject rowObject = new JSONObject(); if (c.getColumnIndex("_id") != -1) { try {//from ww w . j a va2 s . c om rowObject.put("_id", c.getInt(c.getColumnIndex("_id"))); } catch (JSONException e) { e.printStackTrace(); } } for (int i = 0; i < totalColumn; i++) { if (c.getColumnName(i) != null) { String colName = c.getColumnName(i); try { if (c.getString(i) != null) { if (colName.endsWith("_id") || colName.equals("parent")) { if (tableName.equals(DatabaseHelper.BUDGET_TABLE)) { if (colName.equals("parent_budget_id")) { rowObject.put(colName, c.getInt(i)); } else if (!colName.equals("_id")) { String[] entities = c.getString(c.getColumnIndex(colName)).split(","); String keys = ""; for (String entity_id2 : entities) { keys += getRemoteKey(getTableForColName(colName), entity_id2) + ","; } if (keys.endsWith(",")) { keys = keys.substring(0, keys.length() - 1); } rowObject.put(colName, keys); } } else { if (!colName.equals("_id")) { String k = getRemoteKey(getTableForColName(colName), c.getString(i)); if (k != null) { rowObject.put(colName, k); } else { rowObject.put(colName, c.getInt(i)); } } } } else { rowObject.put(colName, c.getString(c.getColumnIndex(colName))); } /****/ if (tableName.equals(DatabaseHelper.ACCOUNT_TABLE)) { String sql = "select max(dateTime) as maxDate, min(dateTime) as minDate from " + DatabaseHelper.TRANSACTION_TABLE + " where from_account_id=" + c.getInt(c.getColumnIndex("_id")); Cursor c2 = db.rawQuery(sql, null); c2.moveToFirst(); rowObject.put("dateOfFirstTransaction", c2.getString(1)); rowObject.put("dateOfLastTransaction", c2.getString(0)); //each account can have a timezone so you can have a balance at closing day rowObject.put("tz", String.valueOf(TimeZone.getDefault().getRawOffset())); } else if (tableName.equals(DatabaseHelper.CATEGORY_TABLE)) { //load parent id Category cat = dba.getCategory(c.getInt(0)); // sql build/load parentId if (cat.getParentId() > 0) { Category pcat = em.load(Category.class, cat.getParentId()); rowObject.put("parent", pcat.remoteKey); rowObject.put("parent_id", pcat.id); } String attrPushString = ""; for (Attribute attr : dba.getAttributesForCategory(c.getInt(0))) { attrPushString = attrPushString + attr.remoteKey + ";"; } if (attrPushString != "") { rowObject.put("attributes", attrPushString); } } else if (tableName.equals(DatabaseHelper.TRANSACTION_TABLE)) { Map<Long, String> attributesMap = dba.getAllAttributesForTransaction(c.getInt(0)); String transaction_attribute = ""; for (long attributeId : attributesMap.keySet()) { transaction_attribute += dba.getAttribute(attributeId).remoteKey + "=" + attributesMap.get(attributeId) + ";"; } rowObject.put("transaction_attribute", transaction_attribute); } /****/ } else { rowObject.put(colName, ""); } } catch (JSONException e) { Log.d(TAG, e.getMessage()); } } } return rowObject; }