List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.ibm.iot.android.iotstarter.utils.MqttHandler.java
/** * Process incoming messages to the MQTT client. * * @param topic The topic the message was received on. * @param mqttMessage The message that was received * @throws Exception Exception that is thrown if the message is to be rejected. *//* ww w . j a va 2 s . c o m*/ @Override public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { Log.d(TAG, ".messageArrived() entered"); int receiveCount = app.getReceiveCount(); app.setReceiveCount(++receiveCount); String runningActivity = app.getCurrentRunningActivity(); if (runningActivity != null && runningActivity.equals(IoTFragment.class.getName())) { Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT); actionIntent.putExtra(Constants.INTENT_DATA, Constants.INTENT_DATA_RECEIVED); context.sendBroadcast(actionIntent); } String payload = new String(mqttMessage.getPayload()); Log.d(TAG, ".messageArrived - Message received on topic " + topic + ": message is " + payload); // TODO: Process message try { // send the message through the application logic MessageConductor.getInstance(context).steerMessage(payload, topic); } catch (JSONException e) { Log.e(TAG, ".messageArrived() - Exception caught while steering a message", e.getCause()); e.printStackTrace(); } }
From source file:com.lge.helloFriendsCamera.MainActivity.java
/** * Send 'take picture' request to camera * - OSC Protocol: osc/commands/execute/*from w w w . j a va 2s . c om*/ * - OSC API: camera.takePicture * - Parameter for 'camera.takePicture': * { * "parameters": { * "sessionId": session ID * } * } * * - Use OSCCommandExecute class for /osc/commands/execute * - OSCCommandsExecute(String command_name, JSONObject parameters); */ private void takePicture() { //Set parameter for camera.takePicture API //Make parameter by using JSONObject OSCCommandsExecute commandsExecute = new OSCCommandsExecute("camera.takePicture", null); commandsExecute.setListener(new HttpAsyncTask.OnHttpListener() { @Override public void onResponse(OSCReturnType type, Object response) { try { JSONObject jObject = new JSONObject((String) response); String state; //Get normal response if (jObject.has(OSCParameterNameMapper.COMMAND_STATE)) { state = jObject.getString(OSCParameterNameMapper.COMMAND_STATE); //Taking picture is on progress if (state.equals(OSCParameterNameMapper.STATE_INPROGRESS)) { String commandId = jObject.getString(OSCParameterNameMapper.COMMAND_ID); checkCommandsStatus(commandId); } else { //Taking picture is finished handleFinishTakePicture((String) response); } } else { //Get error response Toast.makeText(mContext, "[Error] Error occur during taking picture", Toast.LENGTH_LONG) .show(); } } catch (JSONException e) { e.printStackTrace(); } } }); commandsExecute.execute(); }
From source file:com.lge.helloFriendsCamera.MainActivity.java
/** * Check previous api status/*from w w w .j a va 2s . c o m*/ * - OSC Protocol: osc/commands/status * - Parameter for /osc/commands/status: command ID(get from previous /osc/commands/execute) * - Use OSCCommandStatus class for /osc/commands/status * - OSCCommandsStatus(String command_id); */ private void checkCommandsStatus(final String commandId) { OSCCommandsStatus commandsStatus = new OSCCommandsStatus(commandId); commandsStatus.setListener(new HttpAsyncTask.OnHttpListener() { @Override public void onResponse(OSCReturnType type, final Object response) { try { JSONObject jObject = new JSONObject((String) response); String state; //Get normal response if (jObject.has(OSCParameterNameMapper.COMMAND_STATE)) { state = jObject.getString(OSCParameterNameMapper.COMMAND_STATE); //Taking picture is on progress if (state.equals(OSCParameterNameMapper.STATE_INPROGRESS)) { checkCommandsStatus(commandId); } else { //Taking picture is finished handleFinishTakePicture((String) response); } } else {//Get error response Toast.makeText(mContext, "Error occur during taking picture", Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } }); commandsStatus.execute(); }
From source file:com.lge.helloFriendsCamera.MainActivity.java
private void handleFinishTakePicture(String response) { //Finish take picture, then show toast and close session String fileUrl = null;//from w ww . ja va 2s. co m try { JSONObject jObject = new JSONObject((String) response); if (jObject.has(OSCParameterNameMapper.RESULTS)) { JSONObject results = jObject.getJSONObject(OSCParameterNameMapper.RESULTS); fileUrl = results.getString(OSCParameterNameMapper.FILEURL); } } catch (JSONException e) { e.printStackTrace(); } if (fileUrl != null) { Toast.makeText(mContext, "Picture " + fileUrl + " is taken", Toast.LENGTH_LONG).show(); } else { Toast.makeText(mContext, "[Error] Take picture response Error", Toast.LENGTH_LONG).show(); } }
From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java
public static Map<String, String> annotationJSONLookup(String restURL, String... key) { Map<String, String> ret = null; URL url;//from w w w . j av a2 s. c o m HttpURLConnection conn = null; try { if (System.currentTimeMillis() > waitUntil) { url = new URL(restURL); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); BufferedReader in = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String jsonSrc = in.readLine(); in.close(); JSONObject jsonObject = new JSONObject(jsonSrc); ret = new HashMap<String, String>(); for (int i = 0; i < key.length; i++) { Object atr = jsonObject.get(key[i]); String value = ""; if (atr instanceof JSONArray) { JSONArray array = ((JSONArray) atr); for (int j = 0; j < array.length(); j++) { value += array.getString(j); } } else { value = atr.toString(); } if (value.isEmpty()) { value = "No " + key[i] + " found"; } ret.put(key[i], value); } } else { log.warn("Waiting the bioportal server"); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { //wait for 1 minute waitUntil = System.currentTimeMillis() + (1000 * 60); log.error(ioe.getMessage()); } catch (JSONException e) { e.printStackTrace(); } return ret; }
From source file:curso.android.DAO.RespostaDAO.java
public static void insertLista(JSONArray jArray) { Resposta asw = null;// w ww .j a v a2s. c o m JSONObject json = null; try { for (int i = 0; i < jArray.length(); i++) { json = jArray.getJSONObject(i); asw = new Resposta(); asw.setAsk_id(json.getLong("id")); asw.setAsk_id(json.getLong("pergunta")); asw.setUser_id(json.getLong("usuario")); asw.setUser_name(json.getString("user_name")); asw.setAsw_resposta(json.getString("resposta")); insert(asw); json = null; asw = null; } } catch (JSONException e) { e.printStackTrace(); } }
From source file:curso.android.DAO.RespostaDAO.java
public static void atualizaRespostas() { try {// ww w .j a v a2s.c o m deleteAll(); String retorno = Const.webService.doPost(Const.METODO_LISTA_RESPOSTA, new ArrayList<NameValuePair>()); JSONArray jArray = new JSONArray(retorno); RespostaDAO.insertLista(jArray); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.eventattend.portal.bl.FaceBookBL.java
public FaceBookDTO publicProfile(FaceBookDTO faceBookDTO) { FacebookJsonRestClient userClient = null; userClient = getUserClient((String) faceBookDTO.getAccessToken()); EnumSet<ProfileField> fields1 = EnumSet.of(com.google.code.facebookapi.ProfileField.UID, com.google.code.facebookapi.ProfileField.NAME, com.google.code.facebookapi.ProfileField.PIC, com.google.code.facebookapi.ProfileField.ACTIVITIES, com.google.code.facebookapi.ProfileField.AFFILIATIONS, com.google.code.facebookapi.ProfileField.BIRTHDAY, com.google.code.facebookapi.ProfileField.BOOKS, com.google.code.facebookapi.ProfileField.EDUCATION_HISTORY, com.google.code.facebookapi.ProfileField.EMAIL_HASHES, com.google.code.facebookapi.ProfileField.HOMETOWN_LOCATION, com.google.code.facebookapi.ProfileField.HS_INFO, com.google.code.facebookapi.ProfileField.INTERESTS, com.google.code.facebookapi.ProfileField.WALL_COUNT, com.google.code.facebookapi.ProfileField.LOCALE, com.google.code.facebookapi.ProfileField.PIC_BIG, com.google.code.facebookapi.ProfileField.PIC_SMALL_WITH_LOGO, com.google.code.facebookapi.ProfileField.PROFILE_URL, com.google.code.facebookapi.ProfileField.QUOTES, com.google.code.facebookapi.ProfileField.RELATIONSHIP_STATUS, com.google.code.facebookapi.ProfileField.SEX, com.google.code.facebookapi.ProfileField.STATUS, com.google.code.facebookapi.ProfileField.CURRENT_LOCATION, com.google.code.facebookapi.ProfileField.FIRST_NAME, com.google.code.facebookapi.ProfileField.LAST_NAME, com.google.code.facebookapi.ProfileField.HOMETOWN_LOCATION, com.google.code.facebookapi.ProfileField.ABOUT_ME, com.google.code.facebookapi.ProfileField.WORK_HISTORY, com.google.code.facebookapi.ProfileField.PROFILE_URL, com.google.code.facebookapi.ProfileField.MOVIES, com.google.code.facebookapi.ProfileField.EMAIL_HASHES); long facebookUserID = Long.parseLong(faceBookDTO.getProfileId()); JSONArray jsonArray = null;/* w w w .ja va 2 s .c om*/ List currentUser = new ArrayList(); currentUser.add(facebookUserID); try { faceBookDTO = new FaceBookDTO(); jsonArray = userClient.users_getInfo(currentUser, fields1); try { JSONObject obj = jsonArray.getJSONObject(0); faceBookDTO = getUserDetails(obj, faceBookDTO); } catch (JSONException e) { e.printStackTrace(); } } catch (FacebookException e) { e.printStackTrace(); } return faceBookDTO; }
From source file:com.eventattend.portal.bl.FaceBookBL.java
public FaceBookDTO checkAlreadyFriend(FaceBookDTO faceBookDTO) { FacebookJsonRestClient userClient = null; JSONArray jsonArray = null;//ww w. jav a2s . co m userClient = getUserClient((String) faceBookDTO.getAccessToken()); String friendId = faceBookDTO.getProfileId(); System.out.println("Facebook friendId>>> " + friendId); // faceBookDTO = new FaceBookDTO(); faceBookDTO.setProfileId(friendId); try { jsonArray = userClient.friends_get(); } catch (FacebookException e1) { e1.printStackTrace(); } for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); System.out.println("Facebook>>> " + uId); if ((uId.toString()).equals(friendId)) { System.out.println(friendId + " FB Already a Friend !"); faceBookDTO.setAlreadyFriends(true); } System.out.println(">> " + uId); } catch (JSONException e) { e.printStackTrace(); } } return faceBookDTO; }
From source file:com.eventattend.portal.bl.FaceBookBL.java
public FaceBookDTO inviteFriend(FaceBookDTO faceBookDTO) { FacebookJsonRestClient userClient = null; boolean inviteStatus = false; userClient = getUserClient((String) faceBookDTO.getAccessToken()); String friendId = faceBookDTO.getProfileId(); System.out.println("Facebook inviteFriend >>> " + friendId); try {//w ww.j a va2s . c o m JSONObject jsonObject = userClient.notifications_get(); JSONArray jsonArray = jsonObject.getJSONArray("friend_requests"); for (int i = 0; i < jsonArray.length(); i++) { try { Object uId = (Object) jsonArray.get(i); if (uId.toString().equals(friendId)) { System.out.println("Has Already invite you & Accept request in FB >>> " + friendId); inviteStatus = true; } else { inviteStatus = false; } } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } catch (FacebookException e) { inviteStatus = false; e.printStackTrace(); } faceBookDTO.setFriendAlreadyReqYou(inviteStatus); return faceBookDTO; }