List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.ifraag.facebookclient.FacebookClient.java
private Bundle prepBundleStoryWithLoc() { Bundle postParams = new Bundle(); postParams.putString("message", " My Text Message "); /* According to SDK documentation: place object contains id and name of Page associated with this location, and a location field containing geographic information such as latitude, longitude, country */ postParams.putString("place", placePageID); JSONObject coordinates = new JSONObject(); try {//from w ww . ja v a 2 s . c o m coordinates.put("latitude", myLocation.getLatitude()); coordinates.put("longitude", myLocation.getLongitude()); Log.i(FB_CLIENT_TAG, "adding latitude and longitude"); } catch (JSONException e) { e.printStackTrace(); Log.w(FB_CLIENT_TAG, "Exception while adding latitude and longitude"); } postParams.putString("coordinates", coordinates.toString()); return postParams; }
From source file:com.ifraag.facebookclient.FacebookClient.java
private Request prepSearchRequest() { /* Radius of search area in meters. */ final int radius = 1000; /* Maximum number of search results that can be returned. */ final int limitOfResults = 10; Request.GraphPlaceListCallback callback = new Request.GraphPlaceListCallback() { @Override/*www. ja va 2 s . c om*/ public void onCompleted(List<GraphPlace> places, Response response) { try { placePageID = places.get(0).getInnerJSONObject().getString("id"); Log.i(FB_CLIENT_TAG, "Place id is " + placePageID); publishStoryWithLoc(myLocation); } catch (JSONException e) { e.printStackTrace(); /* In case of error cases set page_id to Cairo City is: 115351105145884 or try to get current city id. * TODO: send a link to google map as a facebook post adding marker to current user place. */ placePageID = "115351105145884"; } } }; /* This is the Graph API url that searches for places around your current location: * "search?type=place¢er=30.0380279,31.2405339&distance=1000"*/ return Request.newPlacesSearchRequest(session, myLocation, /* TODO: Error handling may be required */ radius, limitOfResults, null, callback); }
From source file:com.htc.sample.pen.phonegap.PenPlugin.java
private void sendPenEventToJavascript(final String callbackId, final boolean isPenEvent, final boolean isPenButton1, final boolean isPenButton2, final float penPressure) { JSONObject penData = new JSONObject(); try {/*from ww w . ja va2 s . co m*/ penData.put("isPenEvent", isPenEvent); penData.put("isPenButton1", isPenButton1); penData.put("isPenButton2", isPenButton2); penData.put("penPressure", penPressure); } catch (JSONException e) { e.printStackTrace(); } PluginResult result = new PluginResult(PluginResult.Status.OK, penData); result.setKeepCallback(true); success(result, callbackId); }
From source file:nl.hnogames.domoticz.Domoticz.SwitchLogParser.java
@Override public void parseResult(String result) { try {/*from w ww.j a v a 2s . c o m*/ JSONArray jsonArray = new JSONArray(result); ArrayList<SwitchLogInfo> mSwitcheLogs = new ArrayList<>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject row = jsonArray.getJSONObject(i); mSwitcheLogs.add(new SwitchLogInfo(row)); } } switcheLogsReceiver.onReceiveSwitches(mSwitcheLogs); } catch (JSONException e) { Log.e(TAG, "ScenesParser JSON exception"); e.printStackTrace(); switcheLogsReceiver.onError(e); } }
From source file:com.example.jz.mysunshine.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * <p/>/* ww w .j a v a2s .com*/ * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us. */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + "Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.comcast.oscar.sql.queries.DocsisSqlQuery.java
/** * //from w ww . j ava2 s . co m * @param iType * @return JSONObject * @see com.comcast.oscar.dictionary.Dictionary#getTlvDefinition(Integer) */ public JSONObject getTlvDefinition(Integer iType) { JSONObject jsonObj = null; try { jsonObj = recursiveTlvDefinitionBuilder(getMajorParentTlvRowId(iType), MAJOR_TLV, new ArrayList<Integer>()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj; }
From source file:app.sunstreak.yourpisd.net.Student.java
public void loadClassList() throws IOException { String postParams = "{\"studentId\":\"" + studentId + "\"}"; ArrayList<String[]> requestProperties = new ArrayList<String[]>(); requestProperties.add(new String[] { "Content-Type", "application/json" }); HTTPResponse init = Request.sendPost( "https://gradebook.pisd.edu/Pinnacle/Gradebook/InternetViewer/InternetViewerService.ashx/Init?PageUniqueId=" + session.pageUniqueId, session.cookies, requestProperties, true, postParams); String response = init.getData(); int responseCode = init.getResponseCode(); try {// w w w .ja v a2 s . com classList = (new JSONArray(response)).getJSONObject(0).getJSONArray("classes"); } catch (JSONException e) { e.printStackTrace(); System.out.println(response); } }
From source file:app.sunstreak.yourpisd.net.Student.java
public int[] getClassIds() { if (classIds != null) return classIds; if (classList == null) { System.err.println("You didn't login!"); return classIds; }/*from ww w.j a v a 2 s . c o m*/ try { classIds = new int[classList.length()]; for (int i = 0; i < classList.length(); i++) { classIds[i] = classList.getJSONObject(i).getInt("classId"); } } catch (JSONException e) { e.printStackTrace(); } return classIds; }
From source file:app.sunstreak.yourpisd.net.Student.java
public String getClassName(int classIndex) { if (classList == null) return "null"; else//from w w w .ja v a 2s. c o m try { return Parser.toTitleCase(classList.getJSONObject(classIndex).getString("title")); } catch (JSONException e) { e.printStackTrace(); return "jsonException"; } }
From source file:com.henry.ecdemo.ui.chatting.model.DescriptionRxRow.java
@Override public void buildChattingData(final Context context, BaseHolder baseHolder, ECMessage detail, int position) { DescriptionViewHolder holder = (DescriptionViewHolder) baseHolder; ECMessage message = detail;//from ww w. j av a 2 s . c o m if (message != null) { if (message.getType() == ECMessage.Type.TXT) { String msgType = ""; JSONArray jsonArray = null; if (!TextUtils.isEmpty(message.getUserData())) try { JSONObject jsonObject = new JSONObject(message.getUserData()); msgType = jsonObject.getString(CCPChattingFooter2.TXT_MSGTYPE); jsonArray = jsonObject.getJSONArray(CCPChattingFooter2.MSG_DATA); } catch (JSONException e) { e.printStackTrace(); } if (TextUtils.equals(msgType, CCPChattingFooter2.FACETYPE)) { holder.getDescTextView().setBackgroundResource(0); } else { holder.getDescTextView().setBackgroundResource(R.drawable.chat_from_bg_normal); } ECTextMessageBody textBody = (ECTextMessageBody) message.getBody(); String msgTextString = textBody.getMessage(); holder.getDescTextView().showMessage(message.getId() + "", msgTextString, msgType, jsonArray); holder.getDescTextView().setMovementMethod(LinkMovementMethod.getInstance()); View.OnClickListener onClickListener = ((ChattingActivity) context).mChattingFragment .getChattingAdapter().getOnClickListener(); ViewHolderTag holderTag = ViewHolderTag.createTag(message, ViewHolderTag.TagType.TAG_IM_TEXT, position); holder.getDescTextView().setTag(holderTag); holder.getDescTextView().setOnClickListener(onClickListener); } else if (message.getType() == ECMessage.Type.CALL) { ECCallMessageBody textBody = (ECCallMessageBody) message.getBody(); holder.getDescTextView().setText(textBody.getCallText()); holder.getDescTextView().setMovementMethod(LinkMovementMethod.getInstance()); } } }