I put some data in the webservice, here is a snippet:
try { response = UniversalHttpUrlConnection.postJSONObject(ctx.getResources().getString(R.string.delete_one), UniversalHashMapToJSONObjectParams.createObjectForParams(deleteMap)); System.out.println("Response from del task" + response); if(response != null) JSONObject jObj = new JSONObject(response); System.out.println("Deletion" + DatabaseHandler.getInstance(ctx).removeReceipt(receipt)); } catch (JSONException report) { report.printStackTrace(); }
My IDE complains:
if(response != null) JSONObject jObj = new JSONObject(response);
Exact statement: Not an expression . Why is this happening, am I missing something?
if i use:
if (response != null) { JSONObject jObj = new JSONObject(response); }
IDE does not complain.
More details here is my complete method:
public static void deleteReceipt(Receipt receipt, Context ctx) { SessionManager sessionManager; sessionManager = new SessionManager(ctx); HashMap<String, String> map = sessionManager.getUserDetails(); String email = map.get("email"); if (CheckConnection.isNetworkConnected(ctx)) { System.out.println("local id " + receipt._id); Receipt rec = DatabaseHandler.getInstance(ctx).getReceipt(receipt._id); String webReceiptId = rec.web_receipt_id; System.out.println("WebReceipt ID = " + webReceiptId); if (webReceiptId.equalsIgnoreCase("dummy")) { // Delete from local System.out.println("Deletion" + DatabaseHandler.getInstance(ctx).removeReceipt(receipt)); } else { // delete from server // delete from local HashMap<String, String> deleteMap = new HashMap<>(); deleteMap.put("email", email); deleteMap.put("type", "Android"); deleteMap.put("key", Utility.getencryptkey()); deleteMap.put("task_id", webReceiptId); deleteMap.put("receipt_id", String.valueOf(receipt._id)); String response = null; try { response = UniversalHttpUrlConnection.postJSONObject(ctx.getResources().getString(R.string.delete_one), UniversalHashMapToJSONObjectParams.createObjectForParams(deleteMap)); System.out.println("Response from del task" + response); if (response != null) { JSONObject jObj = new JSONObject(response); } System.out.println("Deletion" + DatabaseHandler.getInstance(ctx).removeReceipt(receipt)); } catch (JSONException report) { report.printStackTrace(); } } } }
User3 source share