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:ui.panel.UILicenseAdd.java

private JPanel createPnlFeature() {
    JPanel panel = p.createPanel(Layouts.gridbag);

    GridBagConstraints g = new GridBagConstraints();
    lblSelectFeature = l.createLabel("Select Features", SwingConstants.LEFT);
    g.gridx = 0;/*from w ww .jav  a  2  s .  c o  m*/
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblSelectFeature, g);

    lblServiceApi = l.createLabel("Service APIs Used", SwingConstants.LEFT);
    g.gridx = 4;
    g.gridy = 0;
    g.gridwidth = 2;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(lblServiceApi, g);
    getFeaturesData();
    DefaultMutableTreeNode root = new MyDataNode("Features", "Features");
    for (String key : Data.featureList.keySet()) {
        try {
            DefaultMutableTreeNode element = new MyDataNode(key, Data.fieldNames.get(key));

            JSONArray features = Data.featureList.get(key);
            ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>();

            for (int i = 0; i < features.length(); i++) {
                JSONObject feature = features.getJSONObject(i);
                DefaultMutableTreeNode featureElement = new MyDataNode((String) feature.get("name"),
                        Data.fieldNames.get(feature.get("name")));
                element.add(featureElement);
                arrayFeatureCheckBox.add(featureElement);
            }

            root.add(element);

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

    }

    tree = new JTree(root);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = tree.getSelectionModel().getSelectionPath();
            model.removeAllElements();
            String item = tree.getSelectionModel().getSelectionPath().getLastPathComponent().toString();
            MyDataNode node = (MyDataNode) tree.getSelectionModel().getSelectionPath().getLastPathComponent();
            String selected = node.getValue();
            servicesList = new HashMap<String, String>();
            try {
                if (selected.equalsIgnoreCase("Features")) {
                    for (String key : Data.featureList.keySet()) {
                        JSONArray featureArray = Data.featureList.get(key);

                        for (int i = 0; i < featureArray.length(); i++) {
                            JSONArray servicesArray = featureArray.getJSONObject(i).getJSONArray("services");

                            for (int x = 0; x < servicesArray.length(); x++) {
                                servicesList.put(Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                        servicesArray.getJSONObject(x).getString("name"));
                            }
                        }
                    }
                } else if (path.getPathCount() == 2) {
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(selected)) {
                            JSONArray featureArray = Data.featureList.get(key);

                            for (int i = 0; i < featureArray.length(); i++) {
                                JSONArray servicesArray = featureArray.getJSONObject(i)
                                        .getJSONArray("services");

                                for (int x = 0; x < servicesArray.length(); x++) {
                                    servicesList.put(
                                            Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                            servicesArray.getJSONObject(x).getString("name"));
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                } else {
                    MyDataNode nodePath = (MyDataNode) path.getPathComponent(1);
                    for (String key : Data.featureList.keySet()) {
                        if (key.equals(nodePath.getValue())) {

                            JSONArray featureArray = Data.featureList.get(key);
                            for (int i = 0; i < featureArray.length(); i++) {
                                System.out.println(
                                        featureArray.getJSONObject(i).getString("name") + ":" + selected);
                                if (featureArray.getJSONObject(i).getString("name").equals(selected)) {
                                    JSONArray servicesArray = featureArray.getJSONObject(i)
                                            .getJSONArray("services");
                                    System.out.println(servicesArray);
                                    for (int x = 0; x < servicesArray.length(); x++) {
                                        servicesList.put(
                                                Integer.toString(servicesArray.getJSONObject(x).getInt("id")),
                                                servicesArray.getJSONObject(x).getString("name"));
                                    }
                                } else {
                                    continue;
                                }
                            }
                        } else {
                            continue;
                        }
                    }
                }
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
            for (String serviceKey : servicesList.keySet()) {
                model.addElement(servicesList.get(serviceKey));
            }
            listServiceUsed.setModel(model);
        }
    });
    checkTreeManager = new CheckTreeManager(tree);

    spTreeCheckBox = new JScrollPane(tree);
    spTreeCheckBox.setPreferredSize(new Dimension(300, 300));
    g.gridx = 0;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    g.insets = new Insets(5, 5, 5, 5);
    panel.add(spTreeCheckBox, g);

    model = new DefaultListModel<>();
    model.addElement("");
    listServiceUsed = new JList<String>(model);
    spList = new JScrollPane(listServiceUsed);
    spList.setPreferredSize(new Dimension(300, 300));
    g.gridx = 4;
    g.gridy = 1;
    g.gridwidth = 3;
    g.anchor = g.LINE_START;
    panel.add(spList, g);

    return panel;
}

From source file:ui.panel.UILicenseAdd.java

public JPanel createButtonPanel() {
    JPanel panel = p.createPanel(Layouts.flow);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER));

    btnSubmit = b.createButton("Submit");
    btnCancel = b.createButton("Cancel");

    btnSubmit.addActionListener(new ActionListener() {

        @Override//from ww  w .j a va 2  s.c  o  m
        public void actionPerformed(ActionEvent e) {

            SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {
                    TreePath[] path = checkTreeManager.getSelectionModel().getSelectionPaths();
                    ArrayList<String> featureL = new ArrayList<String>();
                    String[] features = new String[] {};
                    for (TreePath tp : path) {

                        if (tp.getLastPathComponent().toString().equals("Features")) {
                            Object rootNode = tree.getModel().getRoot();
                            int parentCount = tree.getModel().getChildCount(rootNode);
                            for (int i = 0; i < parentCount; i++) {
                                Object parentNode = tree.getModel().getChild(rootNode, i);
                                int childrenCount = tree.getModel().getChildCount(parentNode);

                                for (int x = 0; x < childrenCount; x++) {
                                    MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x);
                                    featureL.add(node.getValue());
                                }
                            }
                        } else if (tp.getPathCount() == 2) {
                            Object rootNode = tree.getModel().getRoot();
                            int parentCount = tree.getModel().getChildCount(rootNode);
                            for (int i = 0; i < parentCount; i++) {
                                Object parentNode = tree.getModel().getChild(rootNode, i);
                                if (parentNode.toString().equals(tp.getLastPathComponent().toString())) {

                                    int childrenCount = tree.getModel().getChildCount(parentNode);

                                    for (int x = 0; x < childrenCount; x++) {
                                        MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x);
                                        featureL.add(node.getValue());
                                    }
                                }
                            }
                        } else if (tp.getPathCount() == 3) {
                            MyDataNode node = (MyDataNode) tp.getLastPathComponent();
                            featureL.add(node.getValue());
                        }

                    }
                    features = featureL.toArray(features);
                    String duration = spnValidity.getValue().toString();
                    if (cbPerpetual.isSelected()) {
                        duration = "-1";
                    }
                    String storage = spnCloud.getValue().toString();
                    String maxVCA = spnConcurrentVCA.getValue().toString();
                    String response = apiCall.addNodeLicense(Data.targetURL, Data.sessionKey, Data.bucketID,
                            features, duration, storage, maxVCA);

                    try {
                        JSONObject responseObject = new JSONObject(response);
                        if (responseObject.get("result").equals("ok")) {
                            Data.mainFrame.uiLicenseDetail.getLicenseData();
                            Data.mainFrame.showPanel("license");
                        }
                    } catch (JSONException e1) {
                        e1.printStackTrace();
                    }
                    return null;
                }
            };
            Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource());
            final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL);

            mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals("state")) {
                        if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
                            dialog.dispose();
                        }
                    }
                }
            });
            mySwingWorker.execute();

            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(progressBar, BorderLayout.CENTER);
            panel.add(new JLabel("Retrieving License..."), BorderLayout.PAGE_START);
            dialog.add(panel);
            dialog.pack();
            dialog.setBounds(50, 50, 300, 100);
            dialog.setLocationRelativeTo(Data.mainFrame);
            dialog.setVisible(true);
        }
    });

    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            Data.mainFrame.showPanel("license");
        }
    });

    panel.add(btnSubmit);
    panel.add(btnCancel);

    return panel;
}

From source file:fr.julienvermet.bugdroid.ui.BugCommentsFragment.java

private void postComment() {
    try {/*from  w ww . j  a v  a2 s  .c om*/
        String message = mCommentMessage.getText().toString();
        if (message.isEmpty()) {
            Toast.makeText(getActivity(), R.string.comment_empty, Toast.LENGTH_LONG).show();
            return;
        }

        mCommentSendProgress.setVisibility(View.VISIBLE);
        mCommentSend.setVisibility(View.GONE);

        JSONObject jsonData = new JSONObject();
        jsonData.put("text", message);

        Intent intent = CommentIntentService.getIntent(getActivity(), mInstance, mBug.bugId, jsonData);
        Messenger messenger = new Messenger(onCommentHandler);
        intent.putExtra(CommentIntentService.MESSENGER, messenger);
        getActivity().startService(intent);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:net.idlesoft.android.apps.github.activities.Profile.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.profile);/*from w  ww  .ja  v  a 2s . c  o  m*/

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi = new GitHubAPI();
    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(Profile.this, Search.class));
        }
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mTarget = extras.getString("username");
    }
    try {
        if ((mTarget == null) || mTarget.equals("")) {
            mTarget = mUsername;
        }
        Response userInfoResp;
        userInfoResp = mGapi.user.info(mTarget);
        if (userInfoResp.statusCode == 200) {
            mJson = new JSONObject(userInfoResp.resp);
        }
        if (mJson == null) {
            // User doesn't really exist, return to the previous activity
            this.setResult(5005);
            finish();
        } else {
            mJson = mJson.getJSONObject("user");

            final JSONArray following_list = new JSONObject(mGapi.user.following(mUsername).resp)
                    .getJSONArray("users");
            final int length = following_list.length() - 1;
            for (int i = 0; i <= length; i++) {
                if (following_list.getString(i).equalsIgnoreCase(mTarget)) {
                }
            }

            String company, location, full_name, email, blog;

            // Replace empty values with "N/A"
            if (mJson.has("company") && !mJson.getString("company").equals("null")
                    && !mJson.getString("company").equals("")) {
                company = mJson.getString("company");
            } else {
                company = "N/A";
            }
            if (mJson.has("location") && !mJson.getString("location").equals("null")
                    && !mJson.getString("location").equals("")) {
                location = mJson.getString("location");
            } else {
                location = "N/A";
            }
            if (mJson.has("name") && !mJson.getString("name").equals("null")) {
                full_name = mJson.getString("name");
            } else {
                full_name = mTarget;
            }
            if (mJson.has("email") && !mJson.getString("email").equals("null")
                    && !mJson.getString("email").equals("")) {
                email = mJson.getString("email");
            } else {
                email = "N/A";
            }
            if (mJson.has("blog") && !mJson.getString("blog").equals("null")
                    && !mJson.getString("blog").equals("")) {
                blog = mJson.getString("blog");
            } else {
                blog = "N/A";
            }

            // Set all the values in the layout
            // ((TextView)findViewById(R.id.tv_top_bar_title)).setText(m_targetUser);
            ((ImageView) findViewById(R.id.iv_user_info_gravatar)).setImageBitmap(GravatarCache.getDipGravatar(
                    GravatarCache.getGravatarID(mTarget), 50.0f, getResources().getDisplayMetrics().density));
            ((TextView) findViewById(R.id.tv_user_info_full_name)).setText(full_name);
            ((TextView) findViewById(R.id.tv_user_info_company)).setText(company);
            ((TextView) findViewById(R.id.tv_user_info_email)).setText(email);
            ((TextView) findViewById(R.id.tv_user_info_location)).setText(location);
            ((TextView) findViewById(R.id.tv_user_info_blog)).setText(blog);

            // Make the buttons work
            final Button activityBtn = (Button) findViewById(R.id.btn_user_info_public_activity);
            final Button repositoriesBtn = (Button) findViewById(R.id.btn_user_info_repositories);
            final Button followersFollowingBtn = (Button) findViewById(R.id.btn_user_info_followers_following);

            activityBtn.setOnClickListener(onButtonClick);
            repositoriesBtn.setOnClickListener(onButtonClick);
            followersFollowingBtn.setOnClickListener(onButtonClick);
        }
    } catch (final JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.facebook.android.FieldsConnectionsDialog.java

public void sortFields(JSONArray jsonFieldsArray) {
    this.fieldsArray = new ArrayList<JSONObject>(jsonFieldsArray.length());
    for (int i = 0; i < jsonFieldsArray.length(); i++) {
        try {/* w  w w.j  a va 2s  . c om*/
            this.fieldsArray.add(jsonFieldsArray.getJSONObject(i));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    Collections.sort(this.fieldsArray, new Comparator<JSONObject>() {
        @Override
        public int compare(JSONObject object1, JSONObject object2) {
            try {
                return object1.getString("name").compareToIgnoreCase(object2.getString("name"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return 0;
        }
    });
}

From source file:com.facebook.android.FieldsConnectionsDialog.java

public void sortConnections(JSONArray jsonConnectionsArray) {
    this.connectionsArray = new ArrayList<String>(jsonConnectionsArray.length());
    for (int i = 0; i < jsonConnectionsArray.length(); i++) {
        try {//ww w.  java2 s.c o  m
            this.connectionsArray.add(jsonConnectionsArray.get(i).toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    Collections.sort(this.connectionsArray);
}

From source file:com.clearner.youtube.GetYouTubePlaylistAsyncTask.java

@Override
protected JSONObject doInBackground(String... params) {
    final String playlistId = params[0];
    if (playlistId == null || playlistId.length() == 0) {
        return null;
    }/*www .  j a  v  a  2  s .  c o  m*/

    if (params.length == 2) {
        final String nextPageToken = params[1];
        if (nextPageToken != null) {
            mUriBuilder.appendQueryParameter("pageToken", nextPageToken);
        }
    }

    mUriBuilder.appendQueryParameter("playlistId", playlistId)
            .appendQueryParameter("part", YOUTUBE_PLAYLIST_PART)
            .appendQueryParameter("maxResults", Integer.toString(YOUTUBE_PLAYLIST_MAX_RESULTS))
            .appendQueryParameter("fields", YOUTUBE_PLAYLIST_FIELDS)
            .appendQueryParameter("key", ApiKey.YOUTUBE_API_KEY);

    final String result = doGetUrl(mUriBuilder.build().toString());
    if (result == null) {
        Log.e(TAG, "Failed to get playlist");
        return null;
    } else {
        //Log.i(TAG, result);
    }

    JSONObject jsonObject;
    try {
        jsonObject = new JSONObject(result);
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }

    return jsonObject;
}

From source file:com.gigathinking.simpleapplock.Upgrade.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 777) {
        if (resultCode == RESULT_OK) {
            int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
            String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
            String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
            if (responseCode == 0) {
                try {
                    JSONObject jo = new JSONObject(purchaseData);
                    String sku = jo.getString("productId");
                    if (sku.equals("no_ads")) {
                        mPrefs.edit().putBoolean("no_ads_purchased", true).commit();
                    }/*from   w ww  . j a v a2  s  . com*/
                    if (sku.equals("adv_prot")) {
                        mPrefs.edit().putBoolean("adv_prot_purchased", true).commit();
                    }
                    Toast.makeText(this, getString(R.string.upgrage_on_next_restart), Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:it.mb.whatshare.Utils.java

/**
 * Encodes the argument <tt>matrix</tt> into a JSON array.
 * /*from  w  ww.j  a  v a2 s . c o  m*/
 * <p>
 * Values are cast to <tt>double</tt> because of JSON lack for a primitive
 * <tt>float</tt> value.
 * 
 * @param matrix
 *            the matrix to be encoded
 * @return the matrix encoded into a JSON array, or <code>null</code> if
 *         <tt>matrix</tt> is <code>null</code> or inconsistent (i.e. it
 *         doesn't contain <tt>float</tt>'s)
 */
public static JSONArray matrixToJson(Matrix matrix) {
    if (matrix == null)
        return null;
    JSONArray array = new JSONArray();
    float[] values = new float[9];
    matrix.getValues(values);
    for (float value : values) {
        try {
            array.put(value);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
    return array;
}

From source file:it.mb.whatshare.Utils.java

/**
 * Decodes a matrix encoded using {@link #matrixToJson(Matrix)} from JSON
 * format to a {@link Matrix} object.// w  w w .  ja v a 2 s. c om
 * 
 * @param array
 *            the encoded matrix
 * @return a matrix containing values from the JSON string (probably not
 *         100% equal to the original because of the
 *         <tt>float --&gt; double --&gt; float</tt> conversion) or
 *         <code>null</code> if <tt>array</tt> is <code>null</code> or
 *         doesn't contain a matrix
 */
public static Matrix jsonToMatrix(JSONArray array) {
    if (array == null)
        return null;
    float[] values = new float[9];
    Matrix matrix = new Matrix();
    for (int i = 0; i < array.length(); i++) {
        try {
            values[i] = (float) array.getDouble(i);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
    matrix.setValues(values);
    return matrix;
}