List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.seanmadden.net.fast.FastInterpretype.java
public void acceptTextSent(String text) { try {/*from www . j a v a 2 s .com*/ int stringBreakLength = config.getInt("StringBreakLength"); if (text.length() > stringBreakLength) { int chunks = text.length() / stringBreakLength; for (int i = 0; i < chunks; i++) { acceptTextSent(text.substring(stringBreakLength * i, stringBreakLength * (i + 1))); } acceptTextSent(text.substring(stringBreakLength * chunks)); return; } if (needToSendDir) { si.sendRawDataToPort(DataPacket.generateUserPayload(mw.getLocalUserName())); } si.sendDataToPort(text); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.seanmadden.net.fast.FastInterpretype.java
public void configEditWindow() { final JFrame frame = new JFrame(); final Vector<ConfigOption> components = new Vector<ConfigOption>(); JPanel buttons = new JPanel(new GridLayout(1, 2)); JButton ok = new JButton("Save"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (ConfigOption config : components) { config.actionPerformed(null); }//from w ww. j a v a2s. com frame.dispose(); try { FileWriter writer = new FileWriter(filename); config.write(writer); writer.flush(); writer.close(); } catch (IOException e1) { e1.printStackTrace(); } catch (JSONException ex) { ex.printStackTrace(); } } }); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }); buttons.add(ok); buttons.add(cancel); Iterator<String> rator = config.keys(); int size = 0; try { while (rator.hasNext()) { String key = (String) rator.next(); ConfigOption config = new ConfigOption(key, this.config.getString(key)); frame.add(config); components.add(config); ++size; } } catch (JSONException e) { e.printStackTrace(); } frame.setLayout(new GridLayout(size + 1, 1)); frame.add(buttons); frame.setSize(300, 400); frame.pack(); frame.setVisible(true); }
From source file:com.acrutiapps.browser.tasks.HistoryBookmarksExportTask.java
private String writeAsJSON(Cursor... params) { try {/*from w w w.j av a 2 s . co m*/ String fileName = mContext.getString(R.string.ApplicationName) + "-" + getNowForFileName() + ".json"; File file = new File(Environment.getExternalStorageDirectory(), fileName); FileWriter writer = new FileWriter(file); FoldersJSONArray foldersArray = new FoldersJSONArray(); BookmarksJSONArray bookmarksArray = new BookmarksJSONArray(); HistoryJSONArray historyArray = new HistoryJSONArray(); Cursor c = params[0]; if (c.moveToFirst()) { int current = 0; int total = c.getCount(); int idIndex = c.getColumnIndex(BookmarksProvider.Columns._ID); int titleIndex = c.getColumnIndex(BookmarksProvider.Columns.TITLE); int urlIndex = c.getColumnIndex(BookmarksProvider.Columns.URL); int creationDateIndex = c.getColumnIndex(BookmarksProvider.Columns.CREATION_DATE); int visitedDateIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITED_DATE); int visitsIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITS); int bookmarkIndex = c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK); int folderIndex = c.getColumnIndex(BookmarksProvider.Columns.IS_FOLDER); int parentfolderIdIndex = c.getColumnIndex(BookmarksProvider.Columns.PARENT_FOLDER_ID); while (!c.isAfterLast()) { publishProgress(1, current, total); boolean isFolder = c.getInt(folderIndex) > 0 ? true : false; if (isFolder) { String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; foldersArray.add(title, c.getLong(idIndex), c.getLong(parentfolderIdIndex)); } else { boolean isBookmark = c.getInt(bookmarkIndex) > 0 ? true : false; String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; String url = c.getString(urlIndex); url = url != null ? URLEncoder.encode(url, "UTF-8") : ""; if (isBookmark) { bookmarksArray.add(c.getLong(parentfolderIdIndex), title, url, c.getLong(creationDateIndex), c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } else { historyArray.add(title, url, c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } } current++; c.moveToNext(); } } JSONObject output = new JSONObject(); output.put("folders", foldersArray); output.put("bookmarks", bookmarksArray); output.put("history", historyArray); writer.write(output.toString(1)); writer.flush(); writer.close(); } catch (JSONException e) { e.printStackTrace(); return e.getMessage(); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); } return null; }
From source file:com.kkurahar.locationmap.JsonParserTask.java
@Override protected String doInBackground(String... params) { String shortUrl = new String(); HttpConnection con = new HttpConnection(); // http?M?iGET?jJSON?iZ?kURL??j String jsonObj = con.doGet(createGetParam(params[0])); // GET?MJSONIuWFNg?uShortUrl?vl?o try {/*from ww w .j a v a 2s. com*/ // ?ubit.ly?vdl JSONObject jsonObject = new JSONObject(jsonObj); JSONObject resultsObject = jsonObject.getJSONObject("results"); JSONObject paramObject = resultsObject.getJSONObject(params[0]); shortUrl = paramObject.getString("shortUrl"); } catch (JSONException e) { e.printStackTrace(); } return shortUrl; }
From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java
/** * Called when JS sends the message.//from w w w .j a v a 2 s. c om * * @param bridge * Receiver instance. * @param code * The code name. This looks like the name of function. * @param message * The message. This looks like the argument of function. This is * usually expressed as JSON. */ @Override public void onArriveMessage(JSBridge bridge, String code, String message) { if (code == null) { } else if (code.equals("onLoad")) { this.mMaptypeList = new ArrayList<ValueText<String>>(); this.mLoaded = true; // executes queued commands. this.execute(null); JSONArray json = null; try { json = new JSONArray(message); } catch (JSONException e) { e.printStackTrace(); } if (json != null) { for (int n = 0; n < json.length(); n++) { JSONObject one = null; try { one = json.getJSONObject(n); } catch (JSONException e) { e.printStackTrace(); } if (one != null) { String id = null, name = null; try { id = one.getString("id"); name = one.getString("name"); } catch (JSONException e) { e.printStackTrace(); } if (id != null && name != null) { this.mMaptypeList.add(new ValueText<String>(id, name)); } } } } // restores map state (2013/08/07) if (this.mInternalMapState != null) { this.restoreMapState(this.mInternalMapState.id, this.mInternalMapState.lon, this.mInternalMapState.lat, this.mInternalMapState.z); this.mInternalMapState = null; } // request to create menu items. this.invalidateOptionsMenuIfPossible(); } else if (code.equals("getCurrentMapState")) { if (message == null || !(message.length() > 0)) { // DOES NOTHING } else { try { JSONObject json = new JSONObject(message); this.mInternalMapState = new MapState(); this.mInternalMapState.id = json.getString("id"); this.mInternalMapState.lat = json.getDouble("lat"); this.mInternalMapState.lon = json.getDouble("lon"); this.mInternalMapState.z = json.getInt("z"); } catch (JSONException e) { e.printStackTrace(); } } this.mWaitingForgetCurrentMapState = false; } else if (code.equals("getCurrentZoomState")) { if (message == null) { // DOES NOTHING } else { try { JSONObject json = new JSONObject(message); this.mZoomState = new ZoomState(); this.mZoomState.minzoom = json.getInt("minzoom"); this.mZoomState.maxzoom = json.getInt("maxzoom"); this.mZoomState.currentzoom = json.getInt("currentzoom"); } catch (JSONException e) { e.printStackTrace(); } this.mWaitingForgetCurrentZoomState = false; } } else if (code.equals("alert")) { // shows alert text. (new AlertDialog.Builder(this)).setTitle(this.getTitle()).setMessage(message != null ? message : "") .setCancelable(true).setPositiveButton(android.R.string.ok, null).show(); } }
From source file:PlayerInfo.Player.java
public JSONObject putBalance(double d) { JSONObject putCurrentBalance = new JSONObject(); try {//w w w . j av a 2 s . c om putCurrentBalance.put("balance", d); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(putCurrentBalance); return putCurrentBalance; }
From source file:com.klinker.android.spotify.loader.OAuthTokenRefresher.java
/** * Decode the response from the input stream= *//*from ww w . j av a 2s . co m*/ protected JSONObject parseResponseObject(InputStream stream) { String jsonString = getJsonString(stream); if (jsonString != null) { try { return new JSONObject(jsonString); } catch (JSONException e) { e.printStackTrace(); return null; } } else { throw new RuntimeException("Unable to get json response array"); } }
From source file:com.ibm.mobilefirst.mobileedge.abstractmodel.MagnetometerData.java
@Override public JSONObject asJSON() { JSONObject json = super.asJSON(); try {/* w ww. j a v a 2 s .c o m*/ JSONObject data = new JSONObject(); data.put("x", x); data.put("y", y); data.put("z", z); json.put("magnometer", data); } catch (JSONException e) { e.printStackTrace(); } return json; }
From source file:com.asd.littleprincesbeauty.data.SqlNote.java
public boolean setContent(JSONObject js) { try {/*from www . j a va 2 s . c o m*/ JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { Log.w(TAG, "cannot set system folder"); } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { // for folder we can only update the snnipet and type String snippet = note.has(NoteColumns.SNIPPET) ? note.getString(NoteColumns.SNIPPET) : ""; if (mIsCreate || !mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); } mSnippet = snippet; int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; if (mIsCreate || mType != type) { mDiffNoteValues.put(NoteColumns.TYPE, type); } mType = type; } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; if (mIsCreate || mId != id) { mDiffNoteValues.put(NoteColumns.ID, id); } mId = id; long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note.getLong(NoteColumns.ALERTED_DATE) : 0; if (mIsCreate || mAlertDate != alertDate) { mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate); } mAlertDate = alertDate; int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext); if (mIsCreate || mBgColorId != bgColorId) { mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId); } mBgColorId = bgColorId; long createDate = note.has(NoteColumns.CREATED_DATE) ? note.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis(); if (mIsCreate || mCreatedDate != createDate) { mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate); } mCreatedDate = createDate; int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note.getInt(NoteColumns.HAS_ATTACHMENT) : 0; if (mIsCreate || mHasAttachment != hasAttachment) { mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment); } mHasAttachment = hasAttachment; long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis(); if (mIsCreate || mModifiedDate != modifiedDate) { mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate); } mModifiedDate = modifiedDate; long parentId = note.has(NoteColumns.PARENT_ID) ? note.getLong(NoteColumns.PARENT_ID) : 0; if (mIsCreate || mParentId != parentId) { mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId); } mParentId = parentId; String snippet = note.has(NoteColumns.SNIPPET) ? note.getString(NoteColumns.SNIPPET) : ""; if (mIsCreate || !mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); } mSnippet = snippet; int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; if (mIsCreate || mType != type) { mDiffNoteValues.put(NoteColumns.TYPE, type); } mType = type; int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID) : AppWidgetManager.INVALID_APPWIDGET_ID; if (mIsCreate || mWidgetId != widgetId) { mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId); } mWidgetId = widgetId; int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE; if (mIsCreate || mWidgetType != widgetType) { mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType); } mWidgetType = widgetType; long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0; if (mIsCreate || mOriginParent != originParent) { mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent); } mOriginParent = originParent; for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); SqlData sqlData = null; if (data.has(DataColumns.ID)) { long dataId = data.getLong(DataColumns.ID); for (SqlData temp : mDataList) { if (dataId == temp.getId()) { sqlData = temp; } } } if (sqlData == null) { sqlData = new SqlData(mContext); mDataList.add(sqlData); } sqlData.setContent(data); } } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); return false; } return true; }
From source file:com.asd.littleprincesbeauty.data.SqlNote.java
public JSONObject getContent() { try {/* w w w .j a v a 2 s. c o m*/ JSONObject js = new JSONObject(); if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); return null; } JSONObject note = new JSONObject(); if (mType == Notes.TYPE_NOTE) { note.put(NoteColumns.ID, mId); note.put(NoteColumns.ALERTED_DATE, mAlertDate); note.put(NoteColumns.BG_COLOR_ID, mBgColorId); note.put(NoteColumns.CREATED_DATE, mCreatedDate); note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment); note.put(NoteColumns.MODIFIED_DATE, mModifiedDate); note.put(NoteColumns.PARENT_ID, mParentId); note.put(NoteColumns.SNIPPET, mSnippet); note.put(NoteColumns.TYPE, mType); note.put(NoteColumns.WIDGET_ID, mWidgetId); note.put(NoteColumns.WIDGET_TYPE, mWidgetType); note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent); js.put(GTaskStringUtils.META_HEAD_NOTE, note); JSONArray dataArray = new JSONArray(); for (SqlData sqlData : mDataList) { JSONObject data = sqlData.getContent(); if (data != null) { dataArray.put(data); } } js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { note.put(NoteColumns.ID, mId); note.put(NoteColumns.TYPE, mType); note.put(NoteColumns.SNIPPET, mSnippet); js.put(GTaskStringUtils.META_HEAD_NOTE, note); } return js; } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } return null; }