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.tweetlanes.android.core.App.java

public void removeAccount(String accountKey) {
    final Editor edit = mPreferences.edit();
    String accountIndices = mPreferences.getString(SharedPreferencesConstants.ACCOUNT_INDICES, null);
    if (accountIndices != null) {
        try {//  w w  w. j a  v a 2 s  .  c o  m
            JSONArray jsonArray = new JSONArray(accountIndices);
            JSONArray newIndicies = new JSONArray();
            for (int i = 0; i < jsonArray.length(); i++) {
                Long id = jsonArray.getLong(i);

                String key = getAccountDescriptorKey(id);
                String jsonAsString = mPreferences.getString(key, null);
                if (jsonAsString != null) {
                    AccountDescriptor account = new AccountDescriptor(this, jsonAsString);

                    if (!account.getAccountKey().equals(accountKey)) {
                        newIndicies.put(Long.toString(id));
                    } else {
                        ArrayList<LaneDescriptor> lanes = account.getAllLaneDefinitions();
                        for (LaneDescriptor lane : lanes) {
                            String lanekey = lane.getCacheKey(account.getScreenName() + account.getId());
                            edit.remove(lanekey);
                        }

                        edit.remove(key);
                        mAccounts.remove(account);
                    }
                }
            }

            accountIndices = newIndicies.toString();
            edit.putString(SharedPreferencesConstants.ACCOUNT_INDICES, accountIndices);

            edit.commit();

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

    updateTwitterAccountCount();
}

From source file:com.tweetlanes.android.core.App.java

void updateTwitterAccountCount() {

    mAccounts.clear();/*w w w.  j  av  a 2 s  .  co m*/

    long currentAccountId = mPreferences.getLong(SharedPreferencesConstants.CURRENT_ACCOUNT_ID, -1);
    String accountIndices = mPreferences.getString(SharedPreferencesConstants.ACCOUNT_INDICES, null);
    if (accountIndices != null) {
        try {
            JSONArray jsonArray = new JSONArray(accountIndices);
            for (int i = 0; i < jsonArray.length(); i++) {
                Long id = jsonArray.getLong(i);

                String key = getAccountDescriptorKey(id);
                String jsonAsString = mPreferences.getString(key, null);
                if (jsonAsString != null) {
                    AccountDescriptor account = new AccountDescriptor(this, jsonAsString);
                    if (Constant.ENABLE_APP_DOT_NET == false
                            && account.getSocialNetType() == SocialNetConstant.Type.Appdotnet) {
                        continue;
                    }
                    mAccounts.add(account);

                    if (currentAccountId != -1 && account.getId() == currentAccountId) {
                        mCurrentAccountIndex = i;
                    }
                }
            }

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

    if (mCurrentAccountIndex == null && mAccounts.size() > 0) {
        mCurrentAccountIndex = 0;
    }
}

From source file:com.tweetlanes.android.core.App.java

public void onPostSignIn(TwitterUser user, String oAuthToken, String oAuthSecret,
        SocialNetConstant.Type oSocialNetType) {

    if (user != null) {

        try {/*from   ww  w .ja  v  a  2s .  com*/

            final Editor edit = mPreferences.edit();
            String userIdAsString = Long.toString(user.getId());

            AccountDescriptor account = new AccountDescriptor(this, user, oAuthToken, oAuthSecret,
                    oSocialNetType, user.getProfileImageUrl(TwitterManager.ProfileImageSize.BIGGER));
            edit.putString(getAccountDescriptorKey(user.getId()), account.toString());

            String accountIndices = mPreferences.getString(SharedPreferencesConstants.ACCOUNT_INDICES, null);
            JSONArray jsonArray;

            if (accountIndices == null) {
                jsonArray = new JSONArray();
                jsonArray.put(0, user.getId());
                mAccounts.add(account);
            } else {
                jsonArray = new JSONArray(accountIndices);
                boolean exists = false;
                for (int i = 0; i < jsonArray.length(); i++) {
                    String c = jsonArray.getString(i);
                    if (c.compareTo(userIdAsString) == 0) {
                        exists = true;
                        mAccounts.set(i, account);
                        break;
                    }
                }

                if (!exists) {
                    jsonArray.put(userIdAsString);
                    mAccounts.add(account);
                }
            }

            accountIndices = jsonArray.toString();
            edit.putString(SharedPreferencesConstants.ACCOUNT_INDICES, accountIndices);

            edit.commit();

            setCurrentAccount(user.getId());

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

        updateTwitterAccountCount();
        if (TwitterManager.get().getSocialNetType() == oSocialNetType) {
            TwitterManager.get().setOAuthTokenWithSecret(oAuthToken, oAuthSecret, true);
        } else {
            TwitterManager.initModule(oSocialNetType,
                    oSocialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY
                            : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY,
                    oSocialNetType == SocialNetConstant.Type.Twitter
                            ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET
                            : ConsumerKeyConstants.APPDOTNET_CONSUMER_SECRET,
                    oAuthToken, oAuthSecret, getCurrentAccountKey(), mConnectionStatusCallbacks);
        }
    }
}

From source file:com.tweetlanes.android.core.App.java

public void setCrittersismMetaData() {
    if (mAccounts.size() > 1) {
        AccountDescriptor account = mAccounts.get(0);
        if (account != null) {
            // Add extra Crittersism meta data
            try {
                JSONObject metadata = new JSONObject();
                metadata.put("FullAccountKey", account.getAccountKey());
                metadata.put("NumberOfAccounts", mAccounts.size());
                for (int i = 1; i < mAccounts.size(); i++) {
                    AccountDescriptor otherAccount = mAccounts.get(i);
                    metadata.put("OtherAccount_" + i, otherAccount.getAccountKey());
                }//w  w  w  .  ja v a 2 s. co  m
                Crittercism.setMetadata(metadata);
                Crittercism.setUsername(account.getAccountKey30Chars());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}

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

private String getErrorMessage(String result) {
    String errorMessage = "";
    try {/*from w w  w  . j  a v a 2 s .c o  m*/

        // Gets the JSON object out of the result string
        String responsejSON = result.substring(result.indexOf("{"), result.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:com.marpies.ane.firebase.auth.utils.FirebaseAuthHelper.java

public void processAuthResponse(@NonNull Task<AuthResult> task, int callbackId) {
    if (task.isSuccessful()) {
        JSONObject response = new JSONObject();
        try {/*  ww  w. j av  a  2 s  .  c  o m*/
            response.put("user", getJSONFromUser(task.getResult().getUser()));
            response.put("callbackId", callbackId);
            AIR.dispatchEvent(FirebaseAuthEvent.SIGN_IN_SUCCESS, response.toString());
        } catch (JSONException e) {
            e.printStackTrace();
            AIR.log("User authentication success, but failed to create response");
            dispatchAuthErrorResponse("Failed to create response.", callbackId);
        }
    } else {
        String errorMessage = (task.getException() != null) ? task.getException().getLocalizedMessage()
                : "Unknown error.";
        AIR.log("Error authenticating user: " + errorMessage);
        dispatchAuthErrorResponse(errorMessage, callbackId);
    }
}

From source file:com.marpies.ane.firebase.auth.utils.FirebaseAuthHelper.java

private String getJSONFromUser(FirebaseUser newUser) {
    FirebaseUser user = (newUser == null) ? getUser() : newUser;
    if (user != null) {
        JSONObject json = new JSONObject();
        try {//www  .ja  va 2 s. co  m
            json.put("uid", user.getUid());
            json.put("isAnonymous", user.isAnonymous());
            if (user.getDisplayName() != null) {
                json.put("displayName", user.getDisplayName());
            }
            if (user.getEmail() != null) {
                json.put("email", user.getEmail());
            }
            if (user.getPhotoUrl() != null) {
                json.put("email", user.getPhotoUrl().toString());
            }
            JSONArray providerData = new JSONArray();
            for (UserInfo userInfo : user.getProviderData()) {
                String userInfoJSON = getJSONFromUserInfo(userInfo);
                if (userInfoJSON != null) {
                    providerData.put(userInfoJSON);
                }
            }
            if (providerData.length() > 0) {
                json.put("providerData", providerData);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json.toString();
    }
    return null;
}

From source file:com.marpies.ane.firebase.auth.utils.FirebaseAuthHelper.java

private String getJSONFromUserInfo(UserInfo userInfo) {
    JSONObject json = new JSONObject();
    try {/*from  w  w  w. ja  v a  2  s  .  com*/
        String providerId = userInfo.getProviderId();
        if (providerId != null) {
            json.put("providerId", providerId);
        }
        String uid = userInfo.getUid();
        if (uid != null) {
            json.put("uid", uid);
        }
        String displayName = userInfo.getDisplayName();
        if (displayName != null) {
            json.put("displayName", displayName);
        }
        String email = userInfo.getEmail();
        if (email != null) {
            json.put("email", email);
        }
        Uri photoURL = userInfo.getPhotoUrl();
        if (photoURL != null) {
            json.put("photoURL", photoURL.toString());
        }
        return json.toString();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

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

@Override
public void parseResult(String result) {

    try {/*from   w  w w. j av a2 s  . c  o m*/
        JSONArray jsonArray = new JSONArray(result);
        ArrayList<WeatherInfo> mWeathers = new ArrayList<>();

        if (jsonArray.length() > 0) {

            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject row = jsonArray.getJSONObject(i);
                mWeathers.add(new WeatherInfo(row));
            }
        }

        WeatherReceiver.onReceiveWeather(mWeathers);

    } catch (JSONException e) {
        Log.e(TAG, "WeatherParser JSON exception");
        e.printStackTrace();
        WeatherReceiver.onError(e);
    }
}

From source file:org.melato.bus.otp.OTPParser.java

public static Plan parse(String data) {
    try {//from   w ww.j  a  va2 s.  c o  m
        Plan plan = new Plan();
        plan.itineraries = new Itinerary[0];
        JSONObject json = new JSONObject(data);
        JSONObject jsonPlan = getObject(json, "plan");
        if (jsonPlan != null) {
            JSONArray jsonItineraries = jsonPlan.getJSONArray("itineraries");
            if (jsonItineraries != null) {
                Itinerary[] itineraries = new Itinerary[jsonItineraries.length()];
                for (int i = 0; i < itineraries.length; i++) {
                    itineraries[i] = parseItinerary(jsonItineraries.getJSONObject(i));
                }
                plan.itineraries = itineraries;
            }
        }
        plan.error = parseError(json);
        return plan;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}