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:org.tomdroid.sync.web.OAuthConnection.java

public Uri getAuthorizationUrl(String server) throws UnknownHostException {

    String url = "";

    // this method shouldn't have been called
    if (isAuthenticated())
        return null;

    rootApi = server + "/api/1.0/";

    AnonymousConnection connection = new AnonymousConnection();
    String response = connection.get(rootApi);

    JSONObject jsonResponse;/*from  w  ww.  j a  v a  2s . c  om*/

    try {
        jsonResponse = new JSONObject(response);

        accessTokenUrl = jsonResponse.getString("oauth_access_token_url");
        requestTokenUrl = jsonResponse.getString("oauth_request_token_url");
        authorizeUrl = jsonResponse.getString("oauth_authorize_url");

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

    OAuthProvider provider = getProvider();

    try {
        // the argument is the callback used when the remote authorization is complete
        url = provider.retrieveRequestToken(consumer, "tomdroid://sync");

        requestToken = consumer.getToken();
        requestTokenSecret = consumer.getTokenSecret();
        oauth10a = provider.isOAuth10a();
        accessToken = "";
        accessTokenSecret = "";
        saveConfiguration();

    } catch (OAuthMessageSignerException e1) {
        e1.printStackTrace();
        return null;
    } catch (OAuthNotAuthorizedException e1) {
        e1.printStackTrace();
        return null;
    } catch (OAuthExpectationFailedException e1) {
        e1.printStackTrace();
        return null;
    } catch (OAuthCommunicationException e1) {
        e1.printStackTrace();
        return null;
    }

    TLog.i(TAG, "Authorization URL : {0}", url);

    return Uri.parse(url);
}

From source file:org.tomdroid.sync.web.OAuthConnection.java

public boolean getAccess(String verifier) throws UnknownHostException {

    TLog.i(TAG, "Verifier: {0}", verifier);

    // this method shouldn't have been called
    if (isAuthenticated())
        return false;

    if (!requestToken.equals("") && !requestTokenSecret.equals("")) {
        consumer.setTokenWithSecret(requestToken, requestTokenSecret);
        TLog.d(TAG, "Added request token {0} and request token secret {1}", requestToken, requestTokenSecret);
    } else//from   w  w w  .ja  v a  2  s  . co  m
        return false;

    OAuthProvider provider = getProvider();

    try {
        provider.retrieveAccessToken(consumer, verifier);
    } catch (OAuthMessageSignerException e1) {
        e1.printStackTrace();
        return false;
    } catch (OAuthNotAuthorizedException e1) {
        e1.printStackTrace();
        return false;
    } catch (OAuthExpectationFailedException e1) {
        e1.printStackTrace();
        return false;
    } catch (OAuthCommunicationException e1) {
        e1.printStackTrace();
        return false;
    }

    // access has been granted, store the access token
    accessToken = consumer.getToken();
    accessTokenSecret = consumer.getTokenSecret();
    requestToken = "";
    requestTokenSecret = "";

    try {
        JSONObject response = new JSONObject(get(rootApi));
        TLog.d(TAG, "Request: {0}", rootApi);

        // append a slash to the url, else the signature will fail
        userApi = response.getJSONObject("user-ref").getString("api-ref");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    saveConfiguration();

    TLog.i(TAG, "Got access token {0}.", consumer.getToken());

    return true;
}

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

private void getSongsList(ArrayList<HashMap<String, String>> parseList, String url) {
    JSONParser jsonParser = new JSONParser();
    JSONArray jsonArray;/*from ww  w .j  a  va  2s.c  om*/

    try {
        JSONObject json = jsonParser.getJSONFromUrl(url);

        if (json != null) {
            jsonArray = json.getJSONArray(mJsonItem);
            int array_length = jsonArray.length();

            if (isSongsView) {
                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, mImageForDB);
                    parseList.add(map);
                }
            } else {
                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.ALBUM, jsonObject.getString(Config.ALBUM));
                    map.put(Config.SONGS_ITEM, jsonObject.getString(Config.SONGS_ITEM));
                    map.put(Config.IMAGE, jsonObject.getString(Config.IMAGE));
                    map.put(Config.URL, jsonObject.getString(Config.URL));
                    parseList.add(map);
                }
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.comcast.oscar.ber.OIDToJSONArray.java

/**
 *
 * @return JSON Array of the OID, DataType and Value */
public JSONArray toJSONArray() {

    JSONArray jaOID = new JSONArray();

    JSONObject joOID = new JSONObject();

    try {//w w w . j a v  a2 s . c  om

        this.sOID = this.sOID.replaceAll("^\\.", "");

        joOID.put(OID, this.sOID);

        joOID.put(DATA_TYPE, this.sDataType);

        //Clean up double quotes in the from and end of string
        this.sValue = this.sValue.replaceAll("^\"|\"$", "");
        joOID.put(VALUE, this.sValue);

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

    return jaOID.put(joOID);
}

From source file:com.plant42.log4j.layouts.JSONLayout.java

/**
 * format a given LoggingEvent to a string, in this case JSONified string
 * @param loggingEvent/* w  w  w.  j  a v a 2s .c  om*/
 * @return String representation of LoggingEvent
 */
@Override
public String format(LoggingEvent loggingEvent) {

    JSONObject root = new JSONObject();

    try {
        //== write basic fields
        writeBasic(root, loggingEvent);

        //== write throwable fields
        writeThrowable(root, loggingEvent);

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

    return root.toString();
}

From source file:com.vk.sdkweb.api.model.VKApiArray.java

@Override
public VKApiModel parse(JSONObject object) {
    try {/*from  w  w  w  . ja  v a  2  s. c  o m*/
        JSONArray jsonArray;
        if ((jsonArray = object.optJSONArray("response")) == null) {
            object = object.getJSONObject("response");
            count = object.getInt("count");
            jsonArray = object.getJSONArray("items");
        }
        parse(jsonArray);

    } catch (JSONException e) {
        if (VKSdk.DEBUG)
            e.printStackTrace();
    }
    fields = object;
    return this;
}

From source file:com.vk.sdkweb.api.model.VKApiArray.java

public void parse(JSONArray jsonArray) {
    items = new ArrayList<T>(jsonArray.length());
    for (int i = 0; i < jsonArray.length(); i++) {
        try {//from w  w w . ja  v  a  2s  . c  o  m
            items.add(parseNextObject(jsonArray.getJSONObject(i)));
        } catch (JSONException e) {
            if (VKSdk.DEBUG)
                e.printStackTrace();
        }
    }
    if (count == 0)
        count = items.size();
}

From source file:com.app.jdy.adapter.DetailAdapter.java

@SuppressLint("ResourceAsColor")
@Override/*from w w  w  .j  a  va2s . c  o m*/
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null || convertView.getTag() == null) {
        // ?list_item
        convertView = listContainer.inflate(this.itemViewResource, null);
        detail_item_title = (TextView) convertView.findViewById(R.id.detail_item_title);
        detail_item_text = (TextView) convertView.findViewById(R.id.detail_item_text);
        detail_linearyout = (LinearLayout) convertView.findViewById(R.id.detail_linearyout);
        try {
            jsonObject = new JSONObject(dataJson);
            product = new JSONObject(jsonObject.getString("product1"));
            productChild = new JSONObject(jsonObject.getString("product2"));
            final String[] urls = { URLs.HTTP + URLs.HOST + product.getString("issuerLogo"),
                    URLs.HTTP + URLs.HOST + product.getString("prodImage") };

            switch (position) {
            case 0:
                showDetail("???", product.getString("name"));
                break;
            case 1:
                showDetail("?", product.getString("issuer"));
                break;
            case 2:
                showDetail("?", product.getString("issuerTypeName"));
                break;
            case 3:
                convertView = listContainer.inflate(R.layout.detail_image_item, null);
                detail_item_title = (TextView) convertView.findViewById(R.id.detail_image_item_title);
                detail_image_item_text = (ImageView) convertView.findViewById(R.id.detail_image_item_text);
                detail_linearyout = (LinearLayout) convertView.findViewById(R.id.detail_linearyout);
                ImageLoader.getInstance().displayImage(urls[0], detail_image_item_text);
                detail_image_item_text.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        imageBrower(0, urls);
                    }
                });
                showDetail("?logo", product.getString("issuerLogo"));
                break;
            case 4:
                convertView = listContainer.inflate(R.layout.detail_image_item, null);
                detail_item_title = (TextView) convertView.findViewById(R.id.detail_image_item_title);
                detail_image_item_text = (ImageView) convertView.findViewById(R.id.detail_image_item_text);
                detail_linearyout = (LinearLayout) convertView.findViewById(R.id.detail_linearyout);
                ImageLoader.getInstance().displayImage(urls[1], detail_image_item_text);
                detail_image_item_text.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        imageBrower(1, urls);
                    }
                });
                showDetail("?", product.getString("prodImage"));
                break;
            case 5:
                showDetail("?()", product.getString("period"));
                break;
            case 6:
                showDetail("", product.getString("profitTypeName"));
                break;
            case 7:
                showDetail("??", product.getString("currencyTypeName"));
                break;
            case 8:
                showDetail("??", product.getString("statusName"));
                break;
            case 9:
                showDetail("?(%)", product.getString("topGain"));
                break;
            case 10:
                showDetail("", product.getString("saleStart"));
                break;
            case 11:
                showDetail("?", product.getString("saleEnd"));
                break;
            case 12:
                showDetail("", product.getString("profitStart"));
                break;
            case 13:
                showDetail("?", product.getString("profitEnd"));
                break;
            case 14:
                showDetail("?", product.getString("investDirection"));
                break;
            case 15:
                showDetail("", product.getString("fundTypeName"));
                break;
            case 16:
                showDetail("?", product.getString("fundDirector"));
                break;
            case 17:
                showDetail("?", product.getString("insuranceTypeName"));
                break;
            case 18:
                choiceType(product.getString("prodTypeCode"), "0", 0);
                break;
            case 19:
                choiceType(product.getString("prodTypeCode"), "1", 1);
                break;
            case 20:
                choiceType(product.getString("prodTypeCode"), "2", 2);
                break;
            case 21:
                choiceType(product.getString("prodTypeCode"), "3", 3);
                break;
            case 22:
                choiceType(product.getString("prodTypeCode"), "4", 4);
                break;
            case 23:
                choiceType(product.getString("prodTypeCode"), "5", 5);
                break;
            case 24:
                choiceType(product.getString("prodTypeCode"), "6", 6);
                break;
            case 25:
                choiceType(product.getString("prodTypeCode"), "7", 7);
                break;
            case 26:
                choiceType(product.getString("prodTypeCode"), "8", 8);
                break;
            case 27:
                choiceType(product.getString("prodTypeCode"), "9", 9);
                break;
            case 28:
                choiceType(product.getString("prodTypeCode"), "10", 10);
                break;
            case 29:
                choiceType(product.getString("prodTypeCode"), "11", 11);
                break;
            case 30:
                choiceType(product.getString("prodTypeCode"), "12", 12);
                break;
            case 31:
                choiceType(product.getString("prodTypeCode"), "13", 13);
                break;
            case 32:
                choiceType(product.getString("prodTypeCode"), "14", 14);
                break;
            case 33:
                choiceType(product.getString("prodTypeCode"), "15", 15);
                break;
            case 34:
                choiceType(product.getString("prodTypeCode"), "16", 16);
                break;
            case 35:
                choiceType(product.getString("prodTypeCode"), "17", 17);
                break;

            default:
                break;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return convertView;
}

From source file:com.google.wave.api.impl.EventMessageBundleSerializer.java

@Override
public Object unmarshall(SerializerState state, Class clazz, Object json) throws UnmarshallException {
    if (!EventMessageBundle.class.isAssignableFrom(clazz)) {
        throw new UnmarshallException(clazz.getName() + " is not assignable from EventMessageBundle");
    }// ww w.  j a  v a 2 s .  c om

    JSONObject jsonObject = (JSONObject) json;
    EventMessageBundle bundle = new EventMessageBundle();
    try {
        bundle.setEvents(
                (List<EventData>) ser.unmarshall(state, List.class, jsonObject.getJSONObject("events")));
        bundle.setWaveletData(
                (WaveletData) ser.unmarshall(state, WaveletData.class, jsonObject.getJSONObject("wavelet")));
        bundle.setBlipData((Map<String, BlipData>) ser.unmarshall(state, Map.class, jsonObject.get("blips")));
    } catch (JSONException jsonx) {
        jsonx.printStackTrace();
    }

    return bundle;
}

From source file:produvia.com.scanner.DevicesActivity.java

/*********************************************************************
 * The WeaverSdk callback indicating that a task has been completed:
 *********************************************************************/
@Override/*w ww . ja  va 2s  . com*/
public void onTaskCompleted(final int flag, final JSONObject response) {
    if (response == null || mActivityPaused)
        return;
    try {

        if (response.has("responseCode") && response.getInt("responseCode") == 401) {
            //unauthorized:
            runWelcomeActivity();
        }

        switch (flag) {
        case WeaverSdk.ACTION_USER_LOGOUT:
            runWelcomeActivity();
            break;

        case WeaverSdk.ACTION_SERVICES_GET:
            if (response.getBoolean("success")) {
                handleReceivedServices(response.getJSONObject("data"));
            }
            break;

        }

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