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:com.dzt.uberclone.HomeFragment.java

private void postSendUberRequest(String json) {
    try {/*from ww w  .jav  a2s. c o  m*/
        JSONObject jsonObject = new JSONObject(json);
        int pendingrideid = jsonObject.getInt("pending_ride_id");
        waitForUberDriver(pendingrideid);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    showMSG("Waiting for a driver to accept");

    requestuber.setVisibility(View.INVISIBLE);
}

From source file:com.dzt.uberclone.HomeFragment.java

private void showShortestTime(String json) {
    try {// w w  w. j av a  2 s .  c o m
        JSONObject jsonObject = new JSONObject(json);
        int shortestTimeTemp = jsonObject.getJSONArray("routes").getJSONObject(0).getJSONArray("legs")
                .getJSONObject(0).getJSONObject("duration").getInt("value");
        shortestTime += shortestTimeTemp;
        ubercount++;
        if (ubercount == nearbyUbers) {
            displayShortestTime(shortestTime, ubercount);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.dzt.uberclone.HomeFragment.java

private void setLocationName(String json) {
    String locationname = "";
    try {// w  ww  .  j a  v  a 2 s.c  om
        JSONObject jsonObject = new JSONObject(json);
        try {

            locationname = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
                    .getString("formatted_address");

        } catch (JSONException e) {
            e.printStackTrace();
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Log.d("location = ", locationname);
    selectPickup.setText(locationname);
    getNearbyUbers();
}

From source file:com.dzt.uberclone.HomeFragment.java

private void showUberMarkers(String json) {
    try {//from  w  w  w. j  a v  a  2 s .co m
        markers.clear();
        shortestTime = 0;
        JSONArray jsonArray = new JSONArray(json);
        nearbyUbers = jsonArray.length();
        ubercount = 0;
        if (nearbyUbers == 0) {
            displayNoUbersMessage();
        }
        for (int i = 0; i < nearbyUbers; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            double lat = jsonObject.getDouble("pos_lat");
            double lon = jsonObject.getDouble("pos_long");
            addUberMarker(lat, lon);
            getShortestTime(lat, lon);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.dzt.uberclone.HomeFragment.java

private void showDriverData(String json) {
    try {/* ww w. j  a v  a  2 s . com*/
        JSONObject jsonObject = new JSONObject(json);
        driverid = jsonObject.getString("driver_id");
        String name = jsonObject.getString("driver_name");
        String lastname = jsonObject.getString("driver_last_name");
        String vehicle = jsonObject.getString("vehicle");
        String plate = jsonObject.getString("license_plate");
        currentRideId = jsonObject.getString("rideid");

        StringBuilder sb = new StringBuilder();
        sb.append("Your driver is ");
        sb.append(name);
        sb.append(" " + lastname);
        sb.append("\n");
        sb.append(vehicle);
        sb.append(" " + plate);

        statusText.setVisibility(View.VISIBLE);
        statusText.setText(sb.toString());

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

}

From source file:com.dzt.uberclone.HomeFragment.java

private void handleDriverTracking(String json) {
    try {/* ww w.  j av a2 s . com*/
        JSONObject jsonObject = new JSONObject(json);
        if (jsonObject.has("fee")) {
            trackDriverBoolean = false;
            double initialLat = jsonObject.getDouble("initial_lat");
            double initialLng = jsonObject.getDouble("initial_lng");
            double finalLat = jsonObject.getDouble("final_lat");
            double finalLng = jsonObject.getDouble("final_lng");
            String distance = jsonObject.getString("distance");
            String time = jsonObject.getString("time");
            String fee = jsonObject.getString("fee");
            String finalFee = jsonObject.getString("final_fee");

            Bundle params = new Bundle();
            params.putString("originText", initialLat + "," + initialLng);
            params.putString("destinationText", finalLat + "," + finalLng);
            params.putString("timeText", time);
            params.putString("distanceText", distance);
            params.putString("feeText", fee);
            params.putString("finalFeeText", finalFee);
            params.putString("rideId", currentRideId);
            /*
                    
            StringBuilder sb = new StringBuilder();
            sb.append("You went from ");
            sb.append(initialLat);
            sb.append(",");
            sb.append(initialLng);
            sb.append(" to ");
            sb.append(finalLat);
            sb.append(",");
            sb.append(finalLng);
            sb.append(". Your time was ");
            sb.append(time);
            sb.append(" minutes and rode a distance of ");
            sb.append(distance);
            sb.append(" KM. Your fee is $");
            sb.append(fee);
            sb.append(" and your adjusted fee is $");
            sb.append(finalFee);
                    
            Log.i("ride details", sb.toString());
            Toast.makeText(getActivity(), sb.toString(), Toast.LENGTH_LONG).show();
                    
            */

            Intent intent = new Intent(getActivity(), RideDetailsActivity.class);
            intent.putExtras(params);
            startActivity(intent);
            getActivity().finish();

        } else {
            double lat = jsonObject.getDouble("latitude");
            double lng = jsonObject.getDouble("longitude");
            addAssignedUberMarker(lat, lng);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.streaming.sweetplayer.fragment.TopFragment.java

private void getTopList() {
    JSONParser jsonParser = new JSONParser();
    JSONArray jsonArray;//from w w w  .  ja v a  2s  .co  m

    try {
        JSONObject json = jsonParser.getJSONFromUrl(Config.TOP_URL);
        if (json != null) {
            jsonArray = json.getJSONArray(Config.SONGS_ITEM);
            int array_length = jsonArray.length();
            if (array_length > 0) {
                for (int i = 0; i < array_length; i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    map.put(Config.ID, jsonObject.getString(Config.ID));
                    map.put(Config.ARTIST, jsonObject.getString(Config.ARTIST));
                    map.put(Config.NAME, jsonObject.getString(Config.SONG));
                    map.put(Config.MP3, jsonObject.getString(Config.MP3));
                    map.put(Config.DURATION, jsonObject.getString(Config.DURATION));
                    map.put(Config.URL, jsonObject.getString(Config.URL));
                    map.put(Config.IMAGE, jsonObject.getString(Config.IMAGE));
                    mTopList.add(map);
                }
            } else {
                // Showing a message should be done in the UI thread.
                mActivity.runOnUiThread(new Runnable() {
                    public void run() {
                        Utils.showUserMessage(mActivity.getApplicationContext(),
                                mActivity.getString(R.string.search_empty));
                    }
                });
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:fi.elfcloud.sci.container.Cluster.java

/**
 * Returns permissions the user has./*from  www.j a  v  a 2  s . co m*/
 * @return 
 */
public String[] getPermissions() {
    String[] array = new String[permissions.length()];
    for (int i = 0; i < this.permissions.length(); i++) {
        try {
            array[i] = this.permissions.getString(i);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return array;
}

From source file:fi.elfcloud.sci.container.Cluster.java

/**
 * Returns child {@link DataItem}s and {@link Cluster}s
 * @return {@link HashMap} with keys <code>clusters</code> and <code>dataitems</code>
 * @throws ECException//  w w w  .  ja  v  a2s .c  o  m
 * @throws IOException
 */
public HashMap<String, Object[]> getElements() throws ECException, IOException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("parent_id", this.id);
    JSONObject response;
    try {
        response = (JSONObject) this.client.getConnection().sendRequest("list_contents", params);
        JSONArray jsonArray = response.getJSONArray("clusters");
        Cluster clusterArray[] = new Cluster[jsonArray.length()];

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            clusterArray[i] = new Cluster(this.client, object);
        }
        this.childCount = clusterArray.length;
        jsonArray = response.getJSONArray("dataitems");
        DataItem dataitemArray[] = new DataItem[jsonArray.length()];
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            dataitemArray[i] = new DataItem(this.client, object, this.id);
        }
        this.dataItemCount = dataitemArray.length;
        HashMap<String, Object[]> objects = new HashMap<String, Object[]>();
        objects.put("clusters", clusterArray);
        objects.put("dataitems", dataitemArray);
        return objects;
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;

}

From source file:fi.elfcloud.sci.container.Cluster.java

/**
 * Returns child {@link Cluster}s /*  ww  w  .  j a  va 2 s .  c o  m*/
 * @return child {@link Cluster}s
 * @throws ECException
 * @throws IOException
 */
public Cluster[] getChildren() throws ECException, IOException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("parent_id", this.id);
    Object response;
    try {
        response = this.client.getConnection().sendRequest("list_clusters", params);
        JSONArray clusters = (JSONArray) response;
        Cluster result[] = new Cluster[clusters.length()];
        for (int i = 0; i < clusters.length(); i++) {
            JSONObject object = clusters.getJSONObject(i);
            result[i] = new Cluster(this.client, object);
        }
        this.childCount = result.length;
        return result;
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}