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:de.dmxcontrol.model.DimmerModel.java

@Override
public void onValueChanged(View v, float x, float y) {
    dimmer[0] = (int) (x * MAX_VALUE);
    try {//from   w ww.ja  va2  s.  c  o  m
        SendData("Intensity", "double", x);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    notifyListener();
}

From source file:com.vk.sdk.api.VKRequest.java

public VKAbstractOperation getOperation() {
    if (this.parseModel) {
        if (this.mModelClass != null) {
            mLoadingOperation = new VKModelOperation(getPreparedRequest(), this.mModelClass);
        } else if (this.mModelParser != null) {
            mLoadingOperation = new VKModelOperation(getPreparedRequest(), this.mModelParser);
        }/*from  w w w . jav a  2 s . c o  m*/
    }
    if (mLoadingOperation == null)
        mLoadingOperation = new VKJsonOperation(getPreparedRequest());
    ((VKJsonOperation) mLoadingOperation).setJsonOperationListener(new VKJSONOperationCompleteListener() {
        @Override
        public void onComplete(VKJsonOperation operation, JSONObject response) {
            if (response.has("error")) {
                try {
                    VKError error = new VKError(response.getJSONObject("error"));
                    if (VKSdk.DEBUG && VKSdk.DEBUG_API_ERRORS) {
                        Log.w(VKSdk.SDK_TAG, operation.getResponseString());
                    }
                    if (processCommonError(error))
                        return;
                    provideError(error);
                } catch (JSONException e) {
                    if (VKSdk.DEBUG)
                        e.printStackTrace();
                }

                return;
            }
            provideResponse(response,
                    mLoadingOperation instanceof VKModelOperation
                            ? ((VKModelOperation) mLoadingOperation).parsedModel
                            : null);
        }

        @Override
        public void onError(VKJsonOperation operation, VKError error) {
            //??? ??? ???????? ????, ??? ????????? ??????????? ????? ??? ??????? ????????
            if (error.errorCode != VKError.VK_CANCELED && error.errorCode != VKError.VK_API_ERROR
                    && operation != null && operation.response != null
                    && operation.response.getStatusLine().getStatusCode() == 200) {
                provideResponse(operation.getResponseJson(), null);
                return;
            }
            if (VKSdk.DEBUG && VKSdk.DEBUG_API_ERRORS && operation != null
                    && operation.getResponseString() != null) {
                Log.w(VKSdk.SDK_TAG, operation.getResponseString());
            }
            if (attempts == 0 || ++mAttemptsUsed < attempts) {
                if (requestListener != null)
                    requestListener.attemptFailed(VKRequest.this, mAttemptsUsed, attempts);
                runOnLooper(new Runnable() {
                    @Override
                    public void run() {
                        start();
                    }
                }, 300);
                return;
            }
            provideError(error);
        }
    });
    return mLoadingOperation;
}

From source file:com.microsoft.office365.starter.models.O365FileListModel.java

private String getErrorMessage(String result) {
    String errorMessage = "";
    try {/*  ww w .  j  a v a  2 s. co m*/
        String responseString = result;
        String responsejSON = responseString.substring(responseString.indexOf("{"), responseString.length());
        JSONObject jObject = new JSONObject(responsejSON);

        JSONObject error = (JSONObject) jObject.get("error");
        errorMessage = error.getString("message");

    } catch (JSONException e) {
        e.printStackTrace();
        errorMessage = e.getMessage();
    }
    return errorMessage;
}

From source file:org.angellist.angellistmobile.Parser.java

public static String parseAccessToken(String json) {
    try {//  w ww. ja va 2s . c  o m
        JSONObject jObject = new JSONObject(json);
        String accessToken = jObject.getString("access_token");
        return accessToken;
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return "";
}

From source file:com.deployd.DeploydObject.java

public DeploydObject(JSONObject obj) {
    String k;// w w w .  ja  va 2s  .  c  om
    while ((k = (String) obj.keys().next()) != NULL) {
        try {
            this.put(k, obj.get(k));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.lgallardo.qbittorrentclient.JSONParser.java

public JSONObject getJSONFromUrl(String url) throws JSONParserStatusCodeException {

    // if server is publish in a subfolder, fix url
    if (subfolder != null && !subfolder.equals("")) {
        url = subfolder + "/" + url;
    }/*from  w w w  .java 2s  .c o  m*/

    HttpResponse httpResponse;
    DefaultHttpClient httpclient;

    HttpParams httpParameters = new BasicHttpParams();

    // Set the timeout in milliseconds until a connection is established.
    // The default value is zero, that means the timeout is not used.
    int timeoutConnection = connection_timeout * 1000;

    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = data_timeout * 1000;

    // Set http parameters
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    HttpProtocolParams.setUserAgent(httpParameters, "qBittorrent for Android");
    HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);

    // Making HTTP request
    HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol);

    // httpclient = new DefaultHttpClient(httpParameters);
    // httpclient = new DefaultHttpClient();
    httpclient = getNewHttpClient();

    httpclient.setParams(httpParameters);

    try {

        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password);

        httpclient.getCredentialsProvider().setCredentials(authScope, credentials);

        // set http parameters

        url = protocol + "://" + hostname + ":" + port + "/" + url;

        //            Log.d("Debug", "url:" + url);

        HttpGet httpget = new HttpGet(url);

        if (this.cookie != null) {
            httpget.setHeader("Cookie", this.cookie);
        }

        httpResponse = httpclient.execute(targetHost, httpget);

        StatusLine statusLine = httpResponse.getStatusLine();

        int mStatusCode = statusLine.getStatusCode();

        if (mStatusCode != 200) {
            httpclient.getConnectionManager().shutdown();
            throw new JSONParserStatusCodeException(mStatusCode);
        }

        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

        // Build JSON
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();

        // try parse the string to a JSON object
        jObj = new JSONObject(json);

    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    } catch (UnsupportedEncodingException e) {
        Log.e("JSON", "UnsupportedEncodingException: " + e.toString());

    } catch (ClientProtocolException e) {
        Log.e("JSON", "ClientProtocolException: " + e.toString());
        e.printStackTrace();
    } catch (SSLPeerUnverifiedException e) {
        Log.e("JSON", "SSLPeerUnverifiedException: " + e.toString());
        throw new JSONParserStatusCodeException(NO_PEER_CERTIFICATE);
    } catch (IOException e) {
        Log.e("JSON", "IOException: " + e.toString());
        // e.printStackTrace();
        httpclient.getConnectionManager().shutdown();
        throw new JSONParserStatusCodeException(TIMEOUT_ERROR);
    } catch (JSONParserStatusCodeException e) {
        httpclient.getConnectionManager().shutdown();
        throw new JSONParserStatusCodeException(e.getCode());
    } catch (Exception e) {
        Log.e("JSON", "Generic: " + e.toString());
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }

    // return JSON String
    return jObj;
}

From source file:com.lgallardo.qbittorrentclient.JSONParser.java

public JSONArray getJSONArrayFromUrl(String url) throws JSONParserStatusCodeException {

    // if server is published in a subfolder, fix url
    if (subfolder != null && !subfolder.equals("")) {
        url = subfolder + "/" + url;
    }//from   w  w  w.  j  av  a 2 s  .  c om

    HttpResponse httpResponse;
    DefaultHttpClient httpclient;

    HttpParams httpParameters = new BasicHttpParams();

    // Set the timeout in milliseconds until a connection is established.
    // The default value is zero, that means the timeout is not used.
    int timeoutConnection = connection_timeout * 1000;

    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = data_timeout * 1000;

    // Set http parameters
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    HttpProtocolParams.setUserAgent(httpParameters, "qBittorrent for Android");
    HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);

    // Making HTTP request
    HttpHost targetHost = new HttpHost(hostname, port, protocol);

    httpclient = getNewHttpClient();

    httpclient.setParams(httpParameters);

    try {

        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

        httpclient.getCredentialsProvider().setCredentials(authScope, credentials);

        url = protocol + "://" + hostname + ":" + port + "/" + url;

        HttpGet httpget = new HttpGet(url);

        if (this.cookie != null) {
            httpget.setHeader("Cookie", this.cookie);
        }

        httpResponse = httpclient.execute(targetHost, httpget);

        StatusLine statusLine = httpResponse.getStatusLine();

        int mStatusCode = statusLine.getStatusCode();

        if (mStatusCode != 200) {
            httpclient.getConnectionManager().shutdown();
            throw new JSONParserStatusCodeException(mStatusCode);
        }

        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

        // Build JSON

        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();

        jArray = new JSONArray(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    } catch (UnsupportedEncodingException e) {
    } catch (ClientProtocolException e) {
        Log.e("JSON", "Client: " + e.toString());
        e.printStackTrace();
    } catch (SSLPeerUnverifiedException e) {
        Log.e("JSON", "SSLPeerUnverifiedException: " + e.toString());
        throw new JSONParserStatusCodeException(NO_PEER_CERTIFICATE);
    } catch (IOException e) {
        Log.e("JSON", "IO: " + e.toString());
        // e.printStackTrace();
        throw new JSONParserStatusCodeException(TIMEOUT_ERROR);
    } catch (JSONParserStatusCodeException e) {
        throw new JSONParserStatusCodeException(e.getCode());
    } catch (Exception e) {
        Log.e("JSON", "Generic: " + e.toString());
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources

        httpclient.getConnectionManager().shutdown();
    }

    // return JSON String
    return jArray;
}

From source file:com.google.ytd.SubmitActivity.java

public void submitToYtdDomain(String ytdDomain, String assignmentId, String videoId, String youTubeName,
        String clientLoginToken, String title, String description, Date dateTaken, String videoLocation,
        String tags) {/* w ww .ja  v a  2 s  . c om*/

    JSONObject payload = new JSONObject();
    try {
        payload.put("method", "NEW_MOBILE_VIDEO_SUBMISSION");
        JSONObject params = new JSONObject();

        params.put("videoId", videoId);
        params.put("youTubeName", youTubeName);
        params.put("clientLoginToken", clientLoginToken);
        params.put("title", title);
        params.put("description", description);
        params.put("videoDate", dateTaken.toString());
        params.put("tags", tags);

        if (videoLocation != null) {
            params.put("videoLocation", videoLocation);
        }

        if (assignmentId != null) {
            params.put("assignmentId", assignmentId);
        }

        payload.put("params", params);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    String jsonRpcUrl = "http://" + ytdDomain + "/jsonrpc";
    String json = Util.makeJsonRpcCall(jsonRpcUrl, payload);

    if (json != null) {
        try {
            JSONObject jsonObj = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.mirasense.scanditsdk.plugin.FullScreenPickerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    JSONObject settings = null;/* ww  w  .  j  a va  2  s  .  c o  m*/
    Bundle options = null;
    Bundle overlayOptions = null;

    if (getIntent().getExtras().containsKey("settings")) {
        try {
            settings = new JSONObject(getIntent().getExtras().getString("settings"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mLegacyMode = false;
    } else {
        mLegacyMode = true;
    }
    if (getIntent().getExtras().containsKey("options")) {
        options = getIntent().getExtras().getBundle("options");
    }
    if (getIntent().getExtras().containsKey("overlayOptions")) {
        overlayOptions = getIntent().getExtras().getBundle("overlayOptions");
    }

    initializeAndStartBarcodeRecognition(settings, options, overlayOptions);
}

From source file:fr.liglab.adele.cilia.workbench.restmonitoring.parser.platform.PlatformChain.java

private static String getJSONname(JSONObject json) {
    try {/*from   w  w  w .  ja  v  a 2 s. c  o  m*/
        return json.getString("ID");
    } catch (JSONException e) {
        e.printStackTrace();
        return "";
    }
}