Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

In this page you can find the example usage for org.json JSONException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:pl.poznan.put.cs.ify.app.fragments.MyGroupsFragment.java

protected void getGroupsMembers() {
    for (GroupModel groupModel : mGroups) {
        if (getActivity() == null) {
            return;
        }/*  w  w  w.j a  v  a 2 s  . com*/
        final String groupName = groupModel.name;
        ServerURLBuilder b = new ServerURLBuilder(getActivity());
        String url = b.getUserInGroup(mUsername, mPassword, groupName);
        Listener<JSONArray> getUsersListener = new Listener<JSONArray>() {

            @Override
            public void onResponse(JSONArray source) {
                JsonParser parser = new JsonParser();
                mProgress--;
                if (mProgress == 0) {
                    mProgressLayout.setVisibility(View.GONE);
                }
                try {
                    ArrayList<UserModel> users = parser.parseGetUsers(source);
                    if (users != null) {
                        for (GroupModel group : mGroups) {
                            if (group.name.equals(groupName)) {
                                group.setUsers(users);
                                mGroupsAdapter.notifyDataSetChanged();
                                return;
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        };
        JsonArrayRequest r = new JsonArrayRequest(url, getUsersListener, mErrorListener);
        mProgress++;
        mProgressLayout.setVisibility(View.VISIBLE);
        QueueSingleton.getInstance(getActivity()).add(r);
    }
}

From source file:org.mitre.svmp.client.IntentHandler.java

public static void inspect(SVMPProtocol.Response response, Context context) {
    SVMPProtocol.Intent intent = response.getIntent();
    switch (intent.getAction()) {
    case ACTION_DIAL:
        Log.d(TAG, String.format("Received 'call' Intent for number '%s'", intent.getData()));
        int telephonyEnabled = isTelephonyEnabled(context);
        if (telephonyEnabled == 0) {
            Intent call = new Intent(Intent.ACTION_CALL);
            call.setData(Uri.parse(intent.getData()));
            context.startActivity(call);
        } else {//from  w  ww . ja v a 2s. co  m
            // phone calls are not supported on this device; send a Toast to
            // the user to let them know
            Toast toast = Toast.makeText(context, telephonyEnabled, Toast.LENGTH_LONG);
            toast.show();
        }
        break;
    case ACTION_VIEW:
        String jsonStr = intent.getData().toString();
        JSONObject jObj = null;
        String message = null;
        try {
            jObj = new JSONObject(jsonStr);
            message = jObj.getString("message");

            if (jObj != null && message != null) {
                switch (message) {
                case "keyboardStarted":

                    InputMethodManager imm = (InputMethodManager) context
                            .getSystemService(context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                    break;

                case "appInstalled":

                    String success = jObj.getString("success");
                    String packageName = jObj.getString("packageId");

                    if (success != null) {
                        if (success.equals("true"))
                            startApp(packageName, context);
                    }
                    break;

                default:
                    break;
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        break;
    default:
        break;
    }
}

From source file:com.fsa.en.dron.activity.MainActivity.java

private void fetchImages() {

    pDialog.setMessage("Levantando vuelo...");
    pDialog.setCanceledOnTouchOutside(false);
    pDialog.show();//  w  ww . j  a va 2  s  .c o  m

    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, endpoint, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    pDialog.hide();
                    JSONArray array = null;

                    try {
                        JSONObject user = response.getJSONObject("photos");
                        array = user.getJSONArray("photo");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    images.clear();
                    for (int i = 0; i < array.length(); i++) {
                        try {
                            JSONObject object = array.getJSONObject(i);
                            Image image = new Image();

                            image.setSmall("https://farm2.staticflickr.com/" + object.getString("server") + "/"
                                    + object.getString("id") + "_" + object.getString("secret") + ".jpg");
                            image.setMedium("https://farm2.staticflickr.com/" + object.getString("server") + "/"
                                    + object.getString("id") + "_" + object.getString("secret") + ".jpg");
                            image.setLarge("https://farm2.staticflickr.com/" + object.getString("server") + "/"
                                    + object.getString("id") + "_" + object.getString("secret") + ".jpg");
                            image.setUrl("https://farm2.staticflickr.com/" + object.getString("server") + "/"
                                    + object.getString("id") + "_" + object.getString("secret") + ".jpg");
                            image.setId(object.getString("id"));
                            Log.i("uuu", "" + "https://farm2.staticflickr.com/" + object.getString("server")
                                    + "/" + object.getString("id") + "_" + object.getString("secret") + ".jpg");
                            images.add(image);

                        } catch (JSONException e) {
                            Log.e(TAG, "Json parsing error: " + e.getMessage());
                        }
                    }

                    mAdapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e(TAG, "Error: " + error.getMessage());
                    pDialog.hide();
                }
            });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req);
}

From source file:com.remobile.file.FileUtils.java

public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) {
    if (!configured) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR,
                "File plugin is not configured. Please see the README.md file for details on how to update config.xml"));
        return true;
    }/*from   www .  ja  v  a 2s . co  m*/
    if (action.equals("testSaveLocationExists")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) {
                boolean b = DirectoryManager.testSaveLocationExists();
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
            }
        }, args, callbackContext);
    } else if (action.equals("getFreeDiskSpace")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) {
                long l = DirectoryManager.getFreeDiskSpace(false);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l));
            }
        }, args, callbackContext);
    } else if (action.equals("testFileExists")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException {
                String fname = args.getString(0);
                boolean b = DirectoryManager.testFileExists(fname);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
            }
        }, args, callbackContext);
    } else if (action.equals("testDirectoryExists")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException {
                String fname = args.getString(0);
                boolean b = DirectoryManager.testFileExists(fname);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
            }
        }, args, callbackContext);
    } else if (action.equals("readAsText")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, MalformedURLException {
                String encoding = args.getString(1);
                int start = args.getInt(2);
                int end = args.getInt(3);
                String fname = args.getString(0);
                readFileAs(fname, start, end, callbackContext, encoding, PluginResult.MESSAGE_TYPE_STRING);
            }
        }, args, callbackContext);
    } else if (action.equals("readAsDataURL")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, MalformedURLException {
                int start = args.getInt(1);
                int end = args.getInt(2);
                String fname = args.getString(0);
                readFileAs(fname, start, end, callbackContext, null, -1);
            }
        }, args, callbackContext);
    } else if (action.equals("readAsArrayBuffer")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, MalformedURLException {
                int start = args.getInt(1);
                int end = args.getInt(2);
                String fname = args.getString(0);
                readFileAs(fname, start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_ARRAYBUFFER);
            }
        }, args, callbackContext);
    } else if (action.equals("readAsBinaryString")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, MalformedURLException {
                int start = args.getInt(1);
                int end = args.getInt(2);
                String fname = args.getString(0);
                readFileAs(fname, start, end, callbackContext, null, PluginResult.MESSAGE_TYPE_BINARYSTRING);
            }
        }, args, callbackContext);
    } else if (action.equals("write")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args)
                    throws JSONException, FileNotFoundException, IOException, NoModificationAllowedException {
                String fname = args.getString(0);
                String data = args.getString(1);
                int offset = args.getInt(2);
                Boolean isBinary = args.getBoolean(3);
                long fileSize = write(fname, data, offset, isBinary);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileSize));
            }
        }, args, callbackContext);
    } else if (action.equals("truncate")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args)
                    throws JSONException, FileNotFoundException, IOException, NoModificationAllowedException {
                String fname = args.getString(0);
                int offset = args.getInt(1);
                long fileSize = truncateFile(fname, offset);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileSize));
            }
        }, args, callbackContext);
    } else if (action.equals("requestAllFileSystems")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws IOException, JSONException {
                callbackContext.success(requestAllFileSystems());
            }
        }, args, callbackContext);
    } else if (action.equals("requestAllPaths")) {
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                try {
                    callbackContext.success(requestAllPaths());
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    } else if (action.equals("requestFileSystem")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws IOException, JSONException {
                int fstype = args.getInt(0);
                long size = args.optLong(1);
                if (size != 0 && size > (DirectoryManager.getFreeDiskSpace(true) * 1024)) {
                    callbackContext.sendPluginResult(
                            new PluginResult(PluginResult.Status.ERROR, FileUtils.QUOTA_EXCEEDED_ERR));
                } else {
                    JSONObject obj = requestFileSystem(fstype);
                    callbackContext.success(obj);
                }
            }
        }, args, callbackContext);
    } else if (action.equals("resolveLocalFileSystemURI")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws IOException, JSONException {
                String fname = args.getString(0);
                JSONObject obj = resolveLocalFileSystemURI(fname);
                callbackContext.success(obj);
            }
        }, args, callbackContext);
    } else if (action.equals("getFileMetadata")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws FileNotFoundException, JSONException, MalformedURLException {
                String fname = args.getString(0);
                JSONObject obj = getFileMetadata(fname);
                callbackContext.success(obj);
            }
        }, args, callbackContext);
    } else if (action.equals("getParent")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, IOException {
                String fname = args.getString(0);
                JSONObject obj = getParent(fname);
                callbackContext.success(obj);
            }
        }, args, callbackContext);
    } else if (action.equals("getDirectory")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException,
                    EncodingException, JSONException {
                String dirname = args.getString(0);
                String path = args.getString(1);
                JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true);
                callbackContext.success(obj);
            }
        }, args, callbackContext);
    } else if (action.equals("getFile")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException,
                    EncodingException, JSONException {
                String dirname = args.getString(0);
                String path = args.getString(1);
                JSONObject obj = getFile(dirname, path, args.optJSONObject(2), false);
                callbackContext.success(obj);
            }
        }, args, callbackContext);
    } else if (action.equals("remove")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, NoModificationAllowedException,
                    InvalidModificationException, MalformedURLException {
                String fname = args.getString(0);
                boolean success = remove(fname);
                if (success) {
                    callbackContext.success();
                } else {
                    callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR);
                }
            }
        }, args, callbackContext);
    } else if (action.equals("removeRecursively")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, FileExistsException, MalformedURLException,
                    NoModificationAllowedException {
                String fname = args.getString(0);
                boolean success = removeRecursively(fname);
                if (success) {
                    callbackContext.success();
                } else {
                    callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR);
                }
            }
        }, args, callbackContext);
    } else if (action.equals("moveTo")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, NoModificationAllowedException, IOException,
                    InvalidModificationException, EncodingException, FileExistsException {
                String fname = args.getString(0);
                String newParent = args.getString(1);
                String newName = args.getString(2);
                JSONObject entry = transferTo(fname, newParent, newName, true);
                callbackContext.success(entry);
            }
        }, args, callbackContext);
    } else if (action.equals("copyTo")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws JSONException, NoModificationAllowedException, IOException,
                    InvalidModificationException, EncodingException, FileExistsException {
                String fname = args.getString(0);
                String newParent = args.getString(1);
                String newName = args.getString(2);
                JSONObject entry = transferTo(fname, newParent, newName, false);
                callbackContext.success(entry);
            }
        }, args, callbackContext);
    } else if (action.equals("readEntries")) {
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws FileNotFoundException, JSONException, MalformedURLException {
                String fname = args.getString(0);
                JSONArray entries = readEntries(fname);
                callbackContext.success(entries);
            }
        }, args, callbackContext);
    } else if (action.equals("_getLocalFilesystemPath")) {
        // Internal method for testing: Get the on-disk location of a local filesystem url.
        // [Currently used for testing file-transfer]
        threadhelper(new FileOp() {
            public void run(JSONArray args) throws FileNotFoundException, JSONException, MalformedURLException {
                String localURLstr = args.getString(0);
                String fname = filesystemPathForURL(localURLstr);
                callbackContext.success(fname);
            }
        }, args, callbackContext);
    } else {
        return false;
    }
    return true;
}

From source file:dk.itu.realms.client.funf.MainPipeline.java

@Override
public void onDataReceived(final Bundle data) {
    try {/*from w ww . j av a  2s .c  o  m*/
        JSONObject dataJson = new JSONObject(getBundleSerializer().serialize(data));
        if (dataJson.getString(Probe.PROBE).equals("edu.mit.media.funf.probe.builtin.LocationProbe")) {
            final Intent intent = new Intent(this, LocationProbeDataService.class);
            intent.putExtra("probeData", getBundleSerializer().serialize(data));

            startService(intent);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:info.aamulumi.tomate.APIConnection.java

/**
 * Send a HTTP request and check the returned element.
 * The JSONObject returned by server must have :
 * - success : int - 1 if request is successful
 *
 * @param url            - url to access
 * @param method         - HTTP method (GET, PUT, ...)
 * @param urlParameters  - parameters send in URL
 * @param bodyParameters - parameters send in body (encoded)
 * @return the list of parsed elements//from  w w w. ja va2 s  . com
 */
public static boolean doHTTPRequest(String url, String method, HashMap<String, String> urlParameters,
        HashMap<String, String> bodyParameters) {
    JSONObject json = makeHttpRequest(url, method, urlParameters, bodyParameters);

    if (json == null)
        return false;
    try {
        int success = json.getInt("success");
        // Parse if successful
        if (success == 1) {
            return true;
        }
    } catch (JSONException e) {
        e.printStackTrace();
        return false;
    }

    return false;
}

From source file:com.github.akinaru.roboticbuttonpusher.bluetooth.BluetoothCustomManager.java

private void dispatchBtDevices(BluetoothDevice device, int rssi, final byte[] scanRecord) {

    if (scanningList.containsKey(device.getAddress())) {

    } else {/*from w w  w.  j a  va  2 s.c o m*/

        Log.v(TAG, "found a new Bluetooth device : " + device.getName() + " : " + device.getAddress());

        scanningList.put(device.getAddress(), device);

        try {
            JSONObject object = new JSONObject();
            object.put(JsonConstants.BT_ADDRESS, device.getAddress());
            object.put(JsonConstants.BT_DEVICE_NAME, device.getName());
            object.put(JsonConstants.BT_ADVERTISING_INTERVAL, -1);

            ArrayList<String> deviceInfo = new ArrayList<>();
            deviceInfo.add(object.toString());

            broadcastUpdateStringList(BluetoothEvents.BT_EVENT_DEVICE_DISCOVERED, deviceInfo);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.chinaftw.music.model.MusicProvider.java

private synchronized void retrieveMedia() {
    try {//ww  w  .  j a  v a2 s .co  m
        if (mCurrentState == State.NON_INITIALIZED) {
            mCurrentState = State.INITIALIZING;

            JSONObject jsonObj = MusicAPI.getPlaylistDetails("60198");
            if (jsonObj == null) {
                return;
            }
            JSONArray tracks = jsonObj.getJSONArray(JSON_TRACKS);
            if (tracks != null) {
                for (int j = 0; j < 20; j++) {
                    MediaMetadata item = buildFromJSON(tracks.getJSONObject(j));
                    String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
                    mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
                }
                buildListsByGenre();
            }
            mCurrentState = State.INITIALIZED;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } finally {
        if (mCurrentState != State.INITIALIZED) {
            // Something bad happened, so we reset state to NON_INITIALIZED to allow
            // retries (eg if the network connection is temporary unavailable)
            mCurrentState = State.NON_INITIALIZED;
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedRefObj.java

public static JSONObject json(Group g) {
    JSONObject obj = new JSONObject();
    try {//w w  w. ja v  a2s. c  om
        obj.put(FEED_ID, g.feedName);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:nl.hnogames.domoticzapi.Parsers.CameraParser.java

@Override
public void parseResult(String result) {
    try {/* w  w  w . j a  va  2s  .c o  m*/
        JSONArray jsonArray = new JSONArray(result);
        ArrayList<CameraInfo> mCameras = new ArrayList<>();
        if (jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject row = jsonArray.getJSONObject(i);
                CameraInfo cameraInfo = new CameraInfo(row);
                cameraInfo.setSnapShotURL(this.domoticz.getSnapshotUrl(cameraInfo));
                if (cameraInfo.getEnabled())
                    mCameras.add(cameraInfo);
            }
        }
        receiver.OnReceiveCameras(mCameras);
    } catch (JSONException e) {
        Log.e(TAG, "CameraParser JSON exception");
        e.printStackTrace();
        receiver.onError(e);
    }
}