List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
public void dropdownBankDeveloperSolicitor() { RequestParams params = null;/*from w ww . j a va 2s. c o m*/ params = new RequestParams(); RestService.post("SPA_Property_GetDropdownValues", params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("Property Activity GetDropdown Success Details "); try { // Create new list jsonlistBank = new ArrayList<HashMap<String, String>>(); jsonResponse = new JSONObject(arg2); JSONArray jsonBank = jsonResponse.getJSONArray("Bank"); for (int j = 0; j < jsonBank.length(); j++) { JSONObject bank = jsonBank.getJSONObject(j); id_b = bank.getString("BankCode").toString(); name_b = bank.getString("BankName").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> bankList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON BANK LIST"); bankList.put("Id_T", id_b); System.out.println(name); bankList.put("Name_T", name_b); System.out.println(name); System.out.println(" END SEND JSON BANK LIST"); jsonlistBank.add(bankList); System.out.println("JSON BANK LIST"); //System.out.println(jsonlistProject); } // Spinner set Array Data in Drop down sAdapBANK = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonlistBank, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertyLSTCHG_BANKNAME.setAdapter(sAdapBANK); for (int j = 0; j < jsonlistBank.size(); j++) { if (jsonlistBank.get(j).get("Name_T").equals(master_bankname)) { spinnerpropertyLSTCHG_BANKNAME.setSelection(j); break; } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(arg2); } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response System.out.println("Property GetDropdown parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
public void dropdownLTY() throws JSONException { RequestParams params = null;/*from www. j a va 2 s . c o m*/ params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "LOAN_PRNCP_TYPE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("Failed"); } @Override protected String parseResponse(String s, boolean b) throws Throwable { return null; } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("Title Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonArraylist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonArraylist.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonArraylist); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonArraylist, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinner_LoanTypeOfLoans.setAdapter(sAdapPROJ); for (int j = 0; j < jsonArraylist.size(); j++) { if (jsonArraylist.get(j).get("Id_T").equals(SLoanTypeOfLoans)) { spinner_LoanTypeOfLoans.setSelection(j); break; } } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
public void dropdownKIV() throws JSONException { RequestParams params = null;//from w ww . ja v a 2s . c om params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "KIVSTATUS"); params.put("sJsonInput", jsonObject.toString()); RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("Failed"); } @Override protected String parseResponse(String s, boolean b) throws Throwable { return null; } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("Title Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonArraylist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonArraylist.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonArraylist); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonArraylist, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinner_kiv.setAdapter(sAdapPROJ); for (int j = 0; j < jsonArraylist.size(); j++) { if (jsonArraylist.get(j).get("Id_T").equals(Skiv)) { spinner_kiv.setSelection(j); break; } } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
public void dropdownstatus() throws JSONException { RequestParams params = null;/*from w ww .j a v a2 s. c om*/ params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "CASESTATUS"); params.put("sJsonInput", jsonObject.toString()); RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("Failed"); } @Override protected String parseResponse(String s, boolean b) throws Throwable { return null; } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("Title Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonArraylist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonArraylist.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonArraylist); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonArraylist, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinner_case_status.setAdapter(sAdapPROJ); for (int j = 0; j < jsonArraylist.size(); j++) { if (jsonArraylist.get(j).get("Id_T").equals(Scase_status)) { spinner_case_status.setSelection(j); break; } } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
private void setvaluestoUI() throws JSONException { RequestParams params = null;// www .ja va 2 s . c om params = new RequestParams(); // Find the SharedPreferences value SharedPreferences prefLoginReturn = getSharedPreferences("LoginData", Context.MODE_PRIVATE); System.out.println("LOGIN DATA"); user_name = prefLoginReturn.getString("sUserName", ""); System.out.println(user_name); Pswd = prefLoginReturn.getString("sPassword", ""); System.out.println(Pswd); catg = prefLoginReturn.getString("sCategory", ""); System.out.println(catg); sUserRole = prefLoginReturn.getString("sUserRole", ""); System.out.println(sUserRole); String sCaseNo = prefLoginReturn.getString("CaseNo", ""); System.out.println(sCaseNo); final JSONObject jsonObject = new JSONObject(); jsonObject.put("CaseNo", sCaseNo); jsonObject.put("UserName", user_name); jsonObject.put("UserRole", sUserRole); params.put("sJsonInput", jsonObject.toString()); RestService.post(METHOD_PROCESS_CASE_DETAILS, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("Failed"); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("property Dropdown Success Details "); System.out.println(arg2); try { JSONArray arrayRes = new JSONArray(arg2); jsonResponseconfirm = arrayRes.getJSONObject(0); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } setallvalues(arg2); } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response JSONArray arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Property Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java
private void setallvalues(String arg2) { JSONArray jObj = null;//from w ww . ja v a 2 s.co m try { jObj = new JSONArray(arg2.toString()); for (int i = 0; i < jObj.length(); i++) { JSONObject jsonobject = jObj.getJSONObject(i); file_open_date.setText(jsonobject.getString("FileOpenDate")); case_file_no.setText(jsonobject.getString("CaseFileNo")); case_type.setText(jsonobject.getString("CaseType")); Scase_status = jsonobject.getString("CaseStatus"); JSONObject obj1 = jsonobject.getJSONObject("LoanPrinciple"); req_for_redemption.getText().toString(); req_for_redemption.setText(obj1.getString("ReqRedStatement")); red_state_date.setText(obj1.getString("RedStmtDate")); red_payment_date.setText(obj1.getString("RedPayDate")); loan_case_no.setText(obj1.getString("LoanCaseNo")); project.setText(obj1.getString("Project")); master_bankname = obj1.getString("MasterBankName"); branch_name.setText(obj1.getString("BranchName")); addr.setText(obj1.getString("Address")); pa_name.setText(obj1.getString("PAName")); bank_ref.setText(obj1.getString("BankRef")); bank_instr_date.setText(obj1.getString("BankInsDate")); letter_offer_date.setText(obj1.getString("LOFDate")); bank_solicitor.setText(obj1.getString("BankSolicitor")); solicitor_loc.setText(obj1.getString("SoliLoc")); solicitor_ref.setText(obj1.getString("SoliRef")); type_facility.setText(obj1.getString("TypeofFacility")); facility_amt.setText(obj1.getString("FacilityAmt")); repayment.setText(obj1.getString("Repaymt")); interest_rate.setText(obj1.getString("IntrstRate")); monthly_installment.setText(obj1.optString("MonthlyInstmt")); term_loanamt.setText(obj1.getString("TermLoanAmt")); interest.setText(obj1.optString("Interest")); od_loan.setText(obj1.getString("ODLoan")); mrta.setText(obj1.getString("MRTA")); bank_guarantee.setText(obj1.optString("BankGuarantee")); letter_credit.setText(obj1.getString("LetterofCredit")); trust_receipt.setText(obj1.optString("TrustReceipt")); others.setText(obj1.getString("Others")); LoanDet1.setText(obj1.getString("LoanDet1")); LoanDet2.setText(obj1.getString("LoanDet2")); LoanDet3.setText(obj1.getString("LoanDet3")); LoanDet4.setText(obj1.getString("LoanDet4")); LoanDet5.setText(obj1.getString("LoanDet5")); Skiv = jsonobject.getString("KIV"); SLoanTypeOfLoans = obj1.getString("TypeofLoan"); if (obj1.getString("RepByFirm").toString().equals("Y")) { rep_firm.setChecked(true); } else { rep_firm.setChecked(false); } } System.out.println(jObj); dropdownstatus(); dropdownKIV(); dropdownLTY(); dropdownBankDeveloperSolicitor(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:es.ucm.look.data.remote.restful.RestMethod.java
/** * To know the 'number' of last id inserted in the Server * /* w ww . j a v a 2s .c o m*/ * @return */ public static int getLastId() { int result = -1; String query = URLEncoder.encode("SELECT e FROM Main e ORDER BY e.id DESC"); String params = "?max=1&query=" + query; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(ConfigNet.getInstance().getURL("mains/" + params)); // Accept Text/plain httpget.addHeader("accept", "application/json"); // Execute the request HttpResponse response; try { response = httpclient.execute(httpget); // Get the response entity HttpEntity entity = response.getEntity(); // If response entity is not null if (entity != null) { // get entity contents and convert it to string InputStream instream = entity.getContent(); String resultResponse = convertStreamToString(instream); // construct a JSON object with result try { // extract field id of the json JSONObject json = new JSONObject(resultResponse); JSONObject mainEntity = json.getJSONObject("main"); result = mainEntity.getInt("id"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Closing the input stream will trigger connection release instream.close(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Return the result return result; }
From source file:com.sogistudio.online.utils.Utils.java
/** * Returns length of jsonArray//w ww.jav a 2 s.co m * * @param json * @return length if parameter is JSON Array, 0 if something else */ public static int getJsonArrayLength(String json) { try { JSONArray jsonArray = new JSONArray(json); return jsonArray.length(); } catch (JSONException e) { e.printStackTrace(); } return 0; }
From source file:fi.harism.lucidchat.api.ChatConnection.java
/** * Handle server event messages.//from ww w . j ava 2s . c o m */ private void handleEvent(String message) { try { // We receive always JSON messages. JSONObject json = new JSONObject(message); // Get event type from JSON. String event = json.optString("event"); // Handle session_created event. if (event.equals("session_created")) { // Here we expect that server sends user_auth only when new // session is created. In case where old session was continues // user_auth ought not to be present. if (!json.has("user_auth")) { // Notify server about connection. mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Session resumed userId=" + mUserId + " sessionId=" + mSessionId)); mObserver.onConnect(mUserId, mUserAuth, mSessionId); } else { // New session was created. mUserId = json.getString("user_id"); mUserAuth = json.getString("user_auth"); mSessionId = json.getString("session_id"); mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Session created userId=" + mUserId + " sessionId=" + mSessionId)); mObserver.onConnect(mUserId, mUserAuth, mSessionId); // If autojoin is enabled send join message. if (mAutojoin) { sendJoinChannel(NINCHAT_LOUNGE); } } } // Handle user_updated and user_found events. if (event.equals("user_updated") || event.equals("user_found")) { String userId = json.getString("user_id"); // If update was sent for ourself. if (userId.equals(mUserId)) { // We do nothing on updates sent to self at the moment. } else { // Notify observer about user updated event. JSONObject userAttrs = json.getJSONObject("user_attrs"); String name = userAttrs.optString("name"); String realName = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); mObserver.onUserUpdated(new User(userId, name, realName, connected)); } } // Handle channel_updated event. if (event.equals("channel_updated")) { String channelId = json.getString("channel_id"); JSONObject channelAttrs = json.getJSONObject("channel_attrs"); String name = channelAttrs.optString("name"); String topic = channelAttrs.optString("topic"); mObserver.onChannelUpdated(new Channel(channelId, name, topic)); } // Handle search_results event. if (event.equals("search_results")) { mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Search results event")); Vector<Channel> channelList = new Vector<Channel>(); // Parse channels from search results. JSONObject channels = json.optJSONObject("channels"); if (channels != null) { JSONArray names = channels.names(); for (int i = 0; i < names.length(); ++i) { String channelId = names.getString(i); JSONObject channelAttrs = channels.getJSONObject(channelId).getJSONObject("channel_attrs"); String name = channelAttrs.optString("name"); String topic = channelAttrs.optString("topic"); channelList.add(new Channel(channelId, name, topic)); } } // Parse users from search results. Vector<User> userList = new Vector<User>(); JSONObject users = json.optJSONObject("users"); if (users != null) { JSONArray names = users.names(); for (int i = 0; i < names.length(); ++i) { String userId = names.getString(i); if (!userId.equals(mUserId)) { JSONObject user = users.getJSONObject(userId); String name = user.optString("name"); String realName = user.optString("realname"); boolean connected = user.optBoolean("connected"); userList.add(new User(userId, name, realName, connected)); } } } mObserver.onSearchResults(channelList, userList); } // Handle channel_joined event. if (event.equals("channel_joined")) { mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Channel joined event")); String channelId = json.getString("channel_id"); Vector<User> userList = new Vector<User>(); JSONObject channelMembers = json.getJSONObject("channel_members"); JSONArray names = channelMembers.names(); for (int i = 0; i < names.length(); ++i) { String userId = names.getString(i); JSONObject userAttrs = channelMembers.getJSONObject(userId).getJSONObject("user_attrs"); if (!userId.equals(mUserId)) { String name = userAttrs.optString("name"); String realName = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); userList.add(new User(userId, name, realName, connected)); } } JSONObject channelAttrs = json.getJSONObject("channel_attrs"); String name = channelAttrs.getString("name"); String topic = channelAttrs.getString("topic"); mObserver.onChannelJoined(new Channel(channelId, name, topic), userList); } // Message receiving happens with 2 callbacks. First // message_received is sent from server and then an empty JSON with // message only. if (event.equals("message_received")) { // Check message_type. We handle only text messages. if (json.optString("message_type").equals("ninchat.com/text")) { mMessage = json; } if (json.optString("message_type").equals("ninchat.com/info")) { mMessage = json; } } // Second part of text message receiving. if (mMessage != null && mMessage.optString("message_type").equals("ninchat.com/text") && json.has("text")) { // Message time is in seconds after epoch. long messageTime = mMessage.getLong("message_time") * 1000; String messageUserName = mMessage.getString("message_user_name"); String channelId = mMessage.optString("channel_id"); String userId = mMessage.optString("user_id"); String text = json.getString("text"); mMessage = null; // If channel_id exists notify observer about channel message. if (channelId.length() > 0) { mObserver.onChannelMessage(channelId, new Message(Message.TYPE_CONVERSATION, messageTime, messageUserName, text)); } // If user_id exists notify observer about private message. if (userId.length() > 0) { User user = new User(userId, messageUserName, "", true); mObserver.onUserMessage(user, new Message(Message.TYPE_CONVERSATION, messageTime, messageUserName, text)); } } if (mMessage != null && mMessage.optString("message_type").equals("ninchat.com/info") && json.has("info")) { String info = json.getString("info"); if (info.equals("join")) { String channelId = mMessage.getString("channel_id"); String userId = json.getString("user_id"); String userName = json.getString("user_name"); mObserver.onInfoJoin(channelId, userId, userName); } if (info.equals("part")) { String channelId = mMessage.getString("channel_id"); String userId = json.getString("user_id"); String userName = json.getString("user_name"); mObserver.onInfoPart(channelId, userId, userName); } mMessage = null; } // Handle channel_parted event. if (event.equals("channel_parted")) { String channelId = json.getString("channel_id"); mObserver.onChannelParted(channelId); } // Handle channel_member_joined. if (event.equals("channel_member_joined")) { String channelId = json.getString("channel_id"); String userId = json.getString("user_id"); JSONObject userAttrs = json.getJSONObject("user_attrs"); String name = userAttrs.getString("name"); String realname = userAttrs.optString("realname"); boolean connected = userAttrs.optBoolean("connected"); mObserver.onUserJoin(channelId, new User(userId, name, realname, connected)); } // Handle channel_member_parted. if (event.equals("channel_member_parted")) { String channelId = json.getString("channel_id"); String userId = json.getString("user_id"); mObserver.onUserPart(channelId, userId); } // Handle second phase of delete_user. if (event.equals("user_deleted")) { mWSC.disconnect(); } } catch (JSONException ex) { ex.printStackTrace(); } }
From source file:fi.harism.lucidchat.api.ChatConnection.java
/** * Send create_session message.//from w w w. j a va 2 s. com */ private void sendCreateSession() { try { mObserver.onServerMessage(new Message(Message.TYPE_LOG, "Send create session")); JSONObject createSession = new JSONObject(); createSession.put("action", "create_session"); // Setting user_id and user_auth will continue existing session. // This happens only when client disconnects unexpectedly. By // default new session is created when application starts. if (mUserId != null && mUserAuth != null) { createSession.put("user_id", mUserId); createSession.put("user_auth", mUserAuth); } else { JSONObject userAttrs = new JSONObject(); userAttrs.put("name", mName); userAttrs.put("realname", mRealName); createSession.put("user_attrs", userAttrs); } JSONArray message_types = new JSONArray(); message_types.put("*"); createSession.put("message_types", message_types); mWSC.send(createSession.toString()); } catch (JSONException ex) { ex.printStackTrace(); } }