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.moode.sms.activity.MainActivity.java

private void notifyUser(Message[] messages) {
    try {/*from   w w  w .  j av a  2  s  .  c  o m*/
        loadUrl("javascript:notify_message_received(" + JsonUtils.parseMessagesToJson(messages) + ")");
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:fr.arnaudguyon.xmltojsonlib.XmlToJson.java

private JSONObject convertTagToJson(Tag tag, boolean isListElement) {
    JSONObject json = new JSONObject();

    // Content is injected as a key/value
    if (tag.getContent() != null) {
        String path = tag.getPath();
        String name = getContentNameReplacement(path, DEFAULT_CONTENT_NAME);
        putContent(path, json, name, tag.getContent());
    }//  w  w w  .  j  av a2s  .c o m

    try {

        HashMap<String, ArrayList<Tag>> groups = tag.getGroupedElements(); // groups by tag names so that we can detect lists or single elements
        for (ArrayList<Tag> group : groups.values()) {

            if (group.size() == 1) { // element, or list of 1
                Tag child = group.get(0);
                if (isForcedList(child)) { // list of 1
                    JSONArray list = new JSONArray();
                    list.put(convertTagToJson(child, true));
                    String childrenNames = child.getName();
                    json.put(childrenNames, list);
                } else { // stand alone element
                    if (child.hasChildren()) {
                        JSONObject jsonChild = convertTagToJson(child, false);
                        json.put(child.getName(), jsonChild);
                    } else {
                        String path = child.getPath();
                        putContent(path, json, child.getName(), child.getContent());
                    }
                }
            } else { // list
                JSONArray list = new JSONArray();
                for (Tag child : group) {
                    list.put(convertTagToJson(child, true));
                }
                String childrenNames = group.get(0).getName();
                json.put(childrenNames, list);
            }
        }
        return json;

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

From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    mActivity.setOnLifeCycleChangeListener(this);

    isChanged = isCloud = false;//from   w ww . j a  v  a 2  s  .c o  m
    // Override the default content view.
    root = (ViewGroup) super.onCreateView(inflater, container, bundle);
    final ImageView moreAlarm = (ImageView) root.findViewById(R.id.more_alarm);
    FragmentChangeActivity.moreAlarm = moreAlarm;
    moreAlarm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (menu.isMenuShowing()) {
                menu.showContent();
            } else {
                menu.showMenu(true);
            }
        }
    });
    // Make the entire view selected when focused.
    moreAlarm.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            v.setSelected(hasFocus);
        }
    });

    addPreferencesFromResource(R.xml.alarm_prefs);
    myUUID = SplashActivity.myUUID;

    // Get each preference so we can retrieve the value later.
    mLabel = findPreference("label");
    mLabel.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            showEditTextPreference(mLabel.getKey(), mLabel.getTitle(), mLabelText);
            return true;
        }
    });

    Preference.OnPreferenceChangeListener preferceChangedListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference p, Object newValue) {
            isChanged = true;
            return true;
        }
    };

    mEnabledPref = (CheckBoxPreference) findPreference("enabled");
    mEnabledPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!isCloud) {
                isChanged = true;
                if ((Boolean) newValue)
                    showCategory();
                else
                    hideCategory();
                return true;
            }
            if ((Boolean) newValue) {
                try {
                    tempjson = new JSONArray("[]");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                selectedDevice = "";
                for (int i = 0; i < json.length(); i++) {
                    if (UIDitems[i].toString().equals(myUUID))
                        checkedItems[i] = true;
                    if (checkedItems[i]) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("name", URLDecoder.decode(items[i].toString()));
                        map.put("uid", UIDitems[i].toString());
                        tempjson.put(map);
                        selectedDevice += items[i] + ", ";
                    }
                }
                if (!selectedDevice.equals(""))
                    selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
            } else {
                try {
                    tempjson = new JSONArray("[]");
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                selectedDevice = "";
                for (int i = 0; i < json.length(); i++) {
                    if (UIDitems[i].toString().equals(myUUID))
                        checkedItems[i] = false;
                    if (checkedItems[i]) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("name", URLDecoder.decode(items[i].toString()));
                        map.put("uid", UIDitems[i].toString());
                        tempjson.put(map);
                        selectedDevice += items[i] + ", ";
                    }
                }
                if (!selectedDevice.equals(""))
                    selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
            }
            mForest.setSummary(selectedDevice);
            isChanged = true;
            return true;
        }
    });
    mTimePref = findPreference("time");
    mVibratePref = (CheckBoxPreference) findPreference("vibrate");
    mVibratePref.setOnPreferenceChangeListener(preferceChangedListener);
    mRepeatPref = findPreference("setRepeat");
    mRepeatPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] values = new String[] {
                    DateUtils.getDayOfWeekString(Calendar.MONDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.TUESDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.WEDNESDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.THURSDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.FRIDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_LONG),
                    DateUtils.getDayOfWeekString(Calendar.SUNDAY, DateUtils.LENGTH_LONG) };
            Intent intent = new Intent(mActivity, RepeatListPreference.class);
            intent.putExtra("key", mRepeatPref.getKey());
            intent.putExtra("title", mRepeatPref.getTitle());
            intent.putExtra("lists", values);
            intent.putExtra("multi", true);
            startActivity(intent);
            return true;
        }
    });
    mForestName = findPreference("forest_name");
    mForest = findPreference("forest");
    mColorPref = (AmbilWarnaPreference) findPreference("color");
    prefs = mActivity.getSharedPreferences("forest", mActivity.MODE_PRIVATE);

    Intent i = mActivity.setAlarmGetIntent;
    mId = i.getIntExtra(Alarms.ALARM_ID, -1);

    alarm = null;
    if (mId == -1) {
        // No alarm id means create a new alarm.
        alarm = new Alarm();
        isChanged = true;
    } else {
        // * load alarm details from database
        alarm = Alarms.getAlarm(mActivity.getContentResolver(), mId);
        // Bad alarm, bail to avoid a NPE.
        if (alarm == null) {
            finish();
            return root;
        }
        isCloud = wasCloud = alarm.cloudEnabled;
    }
    mOriginalAlarm = alarm;

    if (wasCloud) {
        try {
            Log.e("url", " : " + alarm.cloudName);
            json = new JSONArray(prefs.getString(alarm.cloudName + "_registeredDevice", ""));
            String cloud_uid = alarm.cloudUID;
            if (cloud_uid.equals(""))
                cloud_uid = "[]";
            Log.e("url", cloud_uid);
            tempjson = new JSONArray(cloud_uid);
            items = new String[json.length()];
            UIDitems = new CharSequence[json.length()];
            checkedItems = new boolean[json.length()];
            for (int j = 0; j < json.length(); j++) {
                JSONObject jsonObj = json.getJSONObject(j);
                items[j] = jsonObj.getString("name");
                UIDitems[j] = jsonObj.getString("uid");
                checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid"));
            }
        } catch (Exception e) {
            Log.e("url", e.toString());
        }
        selectedDevice = alarm.cloudDevices;
        mForestName.setEnabled(false);
    } else {
        if (prefs.getString("name", "").length() > 0) {
            names = prefs.getString("name", "").substring(1).split("\\|");
            nameCheckedIndex = -1;
        } else
            mForestName.setEnabled(false);
        mForest.setEnabled(false);
    }
    memi_count = alarm.memiCount;
    snooze_strength = alarm.snoozeStrength;
    snooze_count = alarm.snoozeCount;

    updatePrefs(mOriginalAlarm);

    mTimePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            showTimePicker();
            return false;
        }

    });

    mForestName.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            showListPreference(mForestName.getKey(), mForestName.getTitle(), names,
                    String.valueOf(nameCheckedIndex), false);
            return true;
        }
    });

    mForest.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            showListPreference(mForest.getKey(), mForest.getTitle(), items, booleanArrayToString(checkedItems),
                    true);
            return true;
        }
    });
    mColorPref.setOnPreferenceChangeListener(preferceChangedListener);

    // We have to do this to get the save/cancel buttons to highlight on
    // their own.
    ((ListView) root.findViewById(android.R.id.list)).setItemsCanFocus(true);

    // Attach actions to each button.
    View.OnClickListener back_click = new View.OnClickListener() {
        public void onClick(View v) {
            DontSaveDialog(false, null, false);
        }
    };
    ImageView b = (ImageView) root.findViewById(R.id.back);
    b.setOnClickListener(back_click);

    b = (ImageView) root.findViewById(R.id.logo);
    b.setOnClickListener(back_click);

    b = (ImageView) root.findViewById(R.id.alarm_save);
    b.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            saveAlarm();
        }
    });
    b = (ImageView) root.findViewById(R.id.alarm_delete);
    if (mId == -1) {
        b.setEnabled(false);
    } else {
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                deleteAlarm();
            }
        });
    }

    // The last thing we do is pop the time picker if this is a new alarm.
    if (mId == -1) {
        // Assume the user hit cancel
        mTimePickerCancelled = true;
        showTimePicker();
    }

    if (!isCloud && !alarm.enabled)
        hideCategory();

    FragmentChangeActivity.OnNotifyArrived.sendEmptyMessage(0);
    return root;
}

From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java

public static void onActivityResult(String key, String which_str) {
    if (mForestName.getKey().equals(key)) {
        int which = Integer.parseInt(which_str);
        mForestName.setSummary(names[which]);
        String json_string = prefs.getString(names[which] + "_registeredDevice", "");
        if (json_string.equals(""))
            json_string = "[]";
        try {/*from w  w  w  . jav  a 2 s .  c  om*/
            json = new JSONArray(json_string);
            tempjson = new JSONArray("[]");
            items = new String[json.length()];
            UIDitems = new CharSequence[json.length()];
            checkedItems = new boolean[json.length()];
            for (int j = 0; j < json.length(); j++) {
                JSONObject jsonObj = json.getJSONObject(j);
                items[j] = jsonObj.getString("name");
                UIDitems[j] = jsonObj.getString("uid");
                checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        nameCheckedIndex = which;

        selectedDevice = "";
        if (mEnabledPref.isChecked()) {
            for (int i = 0; i < json.length(); i++) {
                if (UIDitems[i].toString().equals(myUUID))
                    checkedItems[i] = true;
                if (checkedItems[i]) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("name", URLDecoder.decode(items[i].toString()));
                    map.put("uid", UIDitems[i].toString());
                    tempjson.put(map);
                    selectedDevice += items[i] + ", ";
                }
            }
        } else {
            for (int i = 0; i < json.length(); i++) {
                if (UIDitems[i].toString().equals(myUUID))
                    checkedItems[i] = false;
                if (checkedItems[i]) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("name", URLDecoder.decode(items[i].toString()));
                    map.put("uid", UIDitems[i].toString());
                    tempjson.put(map);
                    selectedDevice += items[i] + ", ";
                }
            }
        }
        if (!selectedDevice.equals(""))
            selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
        mForest.setSummary(selectedDevice);
        mForest.setEnabled(true);
        isChanged = isCloud = true;

    } else if (mForest.getKey().equals(key)) {
        String[] str_array = which_str.split("\\|");
        boolean[] values = new boolean[str_array.length];
        for (int i = 0; i < str_array.length; i++) {
            values[i] = str_array[i].equals("1");
        }
        checkedItems = values;

        boolean hasMyDevice = false;
        try {
            tempjson = new JSONArray("[]");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        selectedDevice = "";
        for (int i = 0; i < json.length(); i++) {
            if (values[i]) {
                if (UIDitems[i].toString().equals(myUUID))
                    hasMyDevice = true;
                Map<String, String> map = new HashMap<String, String>();
                map.put("name", URLDecoder.decode(items[i].toString()));
                map.put("uid", UIDitems[i].toString());
                tempjson.put(map);
                selectedDevice += items[i] + ", ";
            }
        }
        if (!selectedDevice.equals(""))
            selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2);
        mForest.setSummary(selectedDevice);
        mEnabledPref.setChecked(hasMyDevice);
        isChanged = true;
    } else if (mLabel.getKey().equals(key)) {
        mLabelText = which_str;
        mLabel.setSummary(which_str);
        isChanged = true;
    }
}

From source file:com.sepgil.ral.FetchNodeTask.java

@Override
public void onResponse(JSONObject response) {
    if (mListener == null)
        return;/*from   w  w  w . j a v a2 s  .  c  o m*/
    try {
        mListener.onNodeFetched(new Node(response));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        mListener.onError(ErrorState.ERROR_PARSE);
    }
}

From source file:com.citrus.sdk.payment.PaymentBill.java

public static PaymentBill fromJSON(String json) {
    PaymentBill paymentBill = null;/* www  .j  av  a  2s.c  om*/

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

    if (billObject != null) {
        Amount amount = null;
        String requestSignature = null;
        String merchantTransactionId = null; // TODO: Do the validation of the transaction id length
        String merchantAccessKey = null;
        String returnUrl = null;
        String notifyUrl = null;
        Map<String, String> customParametersMap = null;

        amount = Amount.fromJSONObject(billObject.optJSONObject("amount"));
        requestSignature = billObject.optString("requestSignature");
        merchantTransactionId = billObject.optString("merchantTxnId");
        merchantAccessKey = billObject.optString("merchantAccessKey");
        returnUrl = billObject.optString("returnUrl");
        notifyUrl = billObject.optString("notifyUrl");

        JSONObject customParamsObject = billObject.optJSONObject("customParameters");
        if (customParamsObject != null) {
            customParametersMap = new HashMap<>();
            Iterator<String> iter = customParamsObject.keys();
            while (iter.hasNext()) {
                String key = iter.next();
                String value = customParamsObject.optString(key);

                customParametersMap.put(key, value);
            }
        }

        if (amount != null && requestSignature != null && returnUrl != null && merchantAccessKey != null
                && merchantTransactionId != null) {

            paymentBill = new PaymentBill(amount, requestSignature, merchantTransactionId, merchantAccessKey,
                    returnUrl, notifyUrl, customParametersMap);
        }
    }

    return paymentBill;
}

From source file:com.citrus.sdk.payment.PaymentBill.java

public static JSONObject toJSONObject(PaymentBill paymentBill) {
    JSONObject billObject = null;//from w w  w.j  a v  a 2  s  .  c  o  m

    if (paymentBill != null) {
        Amount amount = paymentBill.getAmount();
        String merchantAccessKey = paymentBill.getMerchantAccessKey();
        String merchantTransactionId = paymentBill.getMerchantTransactionId();
        String requestSignature = paymentBill.getRequestSignature();
        String returnUrl = paymentBill.getReturnUrl();
        String notifyUrl = paymentBill.getNotifyUrl();
        Map<String, String> customParametersMap = paymentBill.getCustomParametersMap();

        if (amount != null && requestSignature != null && merchantAccessKey != null
                && merchantTransactionId != null && returnUrl != null) {

            try {
                billObject = new JSONObject();
                billObject.put("amount", Amount.toJSONObject(amount));
                billObject.put("merchantTxnId", merchantTransactionId);
                billObject.put("merchantAccessKey", merchantAccessKey);
                billObject.put("requestSignature", requestSignature);
                billObject.put("returnUrl", returnUrl);

                if (!TextUtils.isEmpty(notifyUrl)) {
                    billObject.put("notifyUrl", notifyUrl);
                }

                // Putting customParameters
                if (customParametersMap != null && customParametersMap.size() > 0) {
                    JSONObject customParamsObj = new JSONObject();
                    for (Map.Entry<String, String> entry : customParametersMap.entrySet()) {
                        customParamsObj.put(entry.getKey(), entry.getValue());
                    }

                    billObject.put("customParameters", customParamsObj);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    return billObject;
}

From source file:com.citrus.sdk.CitrusActivity.java

private void processresponse(String response, String error) {

    TransactionResponse transactionResponse = null;
    if (!android.text.TextUtils.isEmpty(response)) {
        try {/*from  www.  j  av  a 2 s  .  com*/

            JSONObject redirect = new JSONObject(response);
            mpiServletUrl = redirect.optString("redirectUrl");

            if (!android.text.TextUtils.isEmpty(mpiServletUrl)) {

                mPaymentWebview.loadUrl(mpiServletUrl);
                if (mPaymentOption != null) {
                    EventsManager.logWebViewEvents(CitrusActivity.this, WebViewEvents.OPEN,
                            mPaymentOption.getAnalyticsPaymentType()); //analytics event - WebView Event
                }
            } else {
                transactionResponse = new TransactionResponse(TransactionResponse.TransactionStatus.FAILED,
                        response, mTransactionId);
                sendResult(transactionResponse);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        transactionResponse = new TransactionResponse(TransactionResponse.TransactionStatus.FAILED, error,
                mTransactionId);
        sendResult(transactionResponse);
    }
}

From source file:com.citrus.sdk.CitrusActivity.java

private void prepaidPayment(String response, String error) {

    TransactionResponse transactionResponse = null;
    if (!android.text.TextUtils.isEmpty(response)) {
        try {/*from ww  w. j  av  a 2 s  . c o  m*/

            JSONObject redirect = new JSONObject(response);
            if (!android.text.TextUtils.isEmpty(redirect.getString("redirectUrl"))) {
                setCookie();

                mPaymentWebview.loadUrl(redirect.getString("redirectUrl"));
                if (mPaymentOption != null) {
                    EventsManager.logWebViewEvents(CitrusActivity.this, WebViewEvents.OPEN,
                            mPaymentOption.getAnalyticsPaymentType()); //analytics event
                }
            } else {
                transactionResponse = new TransactionResponse(TransactionResponse.TransactionStatus.FAILED,
                        response, mTransactionId);
                sendResult(transactionResponse);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        transactionResponse = new TransactionResponse(TransactionResponse.TransactionStatus.FAILED, error,
                mTransactionId);
        sendResult(transactionResponse);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    Prefs prefs = GBApplication.getPrefs();
    if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
        return;// w  w  w.  j a  va  2  s  .c om
    }
    if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
        PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powermanager.isScreenOn()) {
            return;
        }
    }

    String messageType = intent.getStringExtra("messageType");
    if (!messageType.equals("PEBBLE_ALERT")) {
        LOG.info("non PEBBLE_ALERT message type not supported");
        return;
    }

    if (!intent.hasExtra("notificationData")) {
        LOG.info("missing notificationData extra");
        return;
    }

    NotificationSpec notificationSpec = new NotificationSpec();
    notificationSpec.id = -1;

    String notificationData = intent.getStringExtra("notificationData");
    try {
        JSONArray notificationJSON = new JSONArray(notificationData);
        notificationSpec.title = notificationJSON.getJSONObject(0).getString("title");
        notificationSpec.body = notificationJSON.getJSONObject(0).getString("body");
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }

    if (notificationSpec.title != null) {
        notificationSpec.type = NotificationType.UNKNOWN;
        String sender = intent.getStringExtra("sender");
        if ("Conversations".equals(sender)) {
            notificationSpec.type = NotificationType.CONVERSATIONS;
        } else if ("OsmAnd".equals(sender)) {
            notificationSpec.type = NotificationType.GENERIC_NAVIGATION;
        }
        GBApplication.deviceService().onNotification(notificationSpec);
    }
}