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:net.homelinux.penecoptero.android.citybikes.app.AccountHelper.java

/**
 * Return a map with subscriber account information
 * @param city The city of the subscription
 * @param subscriberNumber the ID of the subscriber as indicated on his card
 * @param subscriberName The family name of the subscriber
 * @param subscriberPIN The PIN code of the subscriber
 * @return A map with subscriber account information
 *//* w w  w . ja va2  s  .  c o  m*/
public JSONObject getSubscriberAccountInfo(String city, String subscriberNumber, String subscriberName,
        String subscriberPIN) {
    String info = getUrl(SERVER_URL + "/client/" + city + "/info/" + subscriberNumber + "?cltNm="
            + subscriberName + "&cltPin=" + subscriberPIN);
    try {
        return new JSONObject(info);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new JSONObject();
}

From source file:net.homelinux.penecoptero.android.citybikes.app.AccountHelper.java

/**
 * @return Returns a List of cities. Each city is described in a Map of Strings.
 * Each Map contains a "code" value for the city code and a "name" value containing
 * the name of the city.//  w  w w  .j  ava  2s .c o  m
 */
public List<Map<String, String>> getCities() {
    try {
        String citiesString = getUrl(SERVER_URL + "/contracts/full");
        JSONArray cities = new JSONArray(citiesString);
        ArrayList<Map<String, String>> citiesList = new ArrayList<Map<String, String>>();
        for (int i = 0; i < cities.length(); i++) {
            JSONObject city = cities.getJSONObject(i);
            Map<String, String> cityMap = new HashMap<String, String>(2);
            cityMap.put("code", city.getString("code"));
            cityMap.put("name", city.getString("name"));
            citiesList.add(cityMap);
        }
        return citiesList;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return new ArrayList<Map<String, String>>();
    }
}

From source file:bhaskarandroidnannodegree.popularmoviesstage1.asynctasks.FetchTrailReview.java

/**
 * Take the String representing the complete movie list in JSON Format and
 * pull out the data we need to construct the Strings needed for the wireframes.
 * <p>//  w w  w  .j ava 2s  .  c  o m
 * Fortunately parsing is easy:  constructor takes the JSON string and converts it
 * into an Object hierarchy for us.
 */
private void getMovieDataFromJson(String movieJsonStr) throws JSONException {

    // These are the names of the JSON objects that need to be extracted.
    final String NAME = "name";
    final String SIZE = "size";
    final String SOURCE = "source";
    final String TYPE = "type";
    final String REVIEW_ID = "id";
    final String GENRE_ID = "id";
    final String AUTHOR = "author";
    final String CONTENT = "content";
    final String URL = "url";
    final String TOTAL_PAGES_REVIEWS = "total_pages";
    final String TOTAL_RESULTS_REVIEWS = "total_results";
    final String PAGE = "page";
    final String MOVIE_ID = "id";

    final String RESULT1 = "trailers";
    final String RESULT2 = "reviews";
    final String RESULT3 = "genres";
    final String YOUTUBE = "youtube";

    try {
        JSONObject movieJson = new JSONObject(movieJsonStr);
        JSONArray movieArrayTrailer = movieJson.getJSONObject(RESULT1).getJSONArray(YOUTUBE);
        JSONObject movieArrayReviews = movieJson.getJSONObject(RESULT2);
        JSONArray movieArrayGenres = movieJson.getJSONArray(RESULT3);

        String movie_id = movieJson.getString(MOVIE_ID);

        for (int i = 0; i < movieArrayTrailer.length(); i++) {

            JSONObject trailerInfo = movieArrayTrailer.getJSONObject(i);

            String name;
            String size;
            String source;
            String type;
            name = trailerInfo.getString(NAME);
            size = trailerInfo.getString(SIZE);
            source = trailerInfo.getString(SOURCE);
            type = trailerInfo.getString(TYPE);

            TrailerInfo trailer = new TrailerInfo();
            trailer.setName(name);
            trailer.setSize(size);
            trailer.setSource(source);
            trailer.setType(type);

            listTrailers.add(trailer);

        }

        String page = movieArrayReviews.getString(PAGE);
        String total_page = movieArrayReviews.getString(TOTAL_PAGES_REVIEWS);
        String total_results = movieArrayReviews.getString(TOTAL_RESULTS_REVIEWS);

        JSONArray reviews = movieArrayReviews.getJSONArray("results");

        for (int j = 0; j < reviews.length(); j++) {

            JSONObject reviewsInfo = reviews.getJSONObject(j);

            String id;
            String author;
            String content;
            String url;
            id = reviewsInfo.getString(REVIEW_ID);
            author = reviewsInfo.getString(AUTHOR);
            content = reviewsInfo.getString(CONTENT);
            url = reviewsInfo.getString(URL);

            MovieReview review = new MovieReview();
            review.setId(id);
            review.setAuthor(author);
            review.setContent(content);
            review.setUrl(url);

            listMovieReviews.add(review);
        }

        for (int i = 0; i < movieArrayGenres.length(); i++) {

            JSONObject gen = movieArrayGenres.getJSONObject(i);
            String genre_id = gen.getString(GENRE_ID);
            String name = gen.getString(NAME);

        }

    } catch (JSONException e) {
        //Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
}

From source file:org.jandroid2cloud.connection.ChannelHandler.java

@Override
public void message(String rawMsg) {
    logger.debug("Received message from server:" + rawMsg);

    try {/*from   w  ww.ja  v a 2  s  .c  o  m*/
        JSONObject jsonMessage = new JSONObject(new JSONTokener(rawMsg));
        JSONObject links = (JSONObject) jsonMessage.opt("links");
        if (links == null) {
            JSONObject link = jsonMessage.optJSONObject("link");
            handleLink(link);
        } else {
            Iterator it = links.keys();
            while (it.hasNext()) {
                String s = (String) it.next();
                if (s != null && !s.isEmpty()) {
                    JSONObject o = links.getJSONObject(s);
                    handleLink(o);
                }
            }
        }

        Map<String, String> params = new HashMap<String, String>();
        params.put("links", rawMsg);
        String response = oauth.makeRequest("http://" + config.getHost() + "/markread", Verb.POST, params);
        logger.debug("Marked message as read");
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (NetworkException e) {
        logger.error(NotificationAppender.MARKER, "Could not mark links as read.\n"
                + "You will not receive more links until that is done.\n" + "See log for details", e);
    }
}

From source file:org.openhab.habdroid.model.OpenHABNotification.java

public OpenHABNotification(JSONObject jsonObject) {
    try {/*from  w w  w .ja  va 2 s.  c  o  m*/
        if (jsonObject.has("icon"))
            this.setIcon(jsonObject.getString("icon"));
        if (jsonObject.has("severity"))
            this.setSeverity(jsonObject.getString("severity"));
        if (jsonObject.has("message"))
            this.setMessage(jsonObject.getString("message"));
        if (jsonObject.has("created")) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            this.setCreated(format.parse(jsonObject.getString("created")));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:edu.umass.cs.reconfiguration.examples.noop.NoopAppCoordinator.java

@SuppressWarnings("deprecation")
@Override//ww w.j a  v  a  2 s  . c  o  m
public boolean coordinateRequest(Request request, ExecutedCallback callback)
        throws IOException, RequestParseException {
    try {
        // coordinate exactly once, and set self to entry replica
        if (request instanceof ReplicableRequest)
            ((ReplicableRequest) request).setNeedsCoordination(false);
        if (request instanceof NoopAppRequest)
            ((NoopAppRequest) request).setEntryReplica(this.getMyID());
        // pick lazy or paxos coordinator, the defaults supported
        if (this.coordType.equals(CoordType.LAZY))
            this.sendAllLazy(request);
        else if (this.coordType.equals(CoordType.PAXOS)) {
            super.coordinateRequest(request, callback);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:cn.com.jinyinmao.app.openapi.WBInviteAPIActivity.java

/**
 *  /*from   w  ww.j  a v a 2s  . c  om*/
 */
@Override
public void onClick(View v) {

    //  JSON ?
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put(InviteAPI.KEY_TEXT, "??");
        jsonObject.put(InviteAPI.KEY_URL, "http://app.sina.com.cn/appdetail.php?appID=770915");
        jsonObject.put(InviteAPI.KEY_INVITE_LOGO, "http://hubimage.com2us.com/hubweb/contents/123_499.jpg");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    // ? Uid
    String uid = mEditText.getText().toString();
    //String uid = "2785593564";

    // ? Token
    Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(WBInviteAPIActivity.this);
    if (accessToken != null && accessToken.isSessionValid()) {
        //  OpenAPI ???
        new InviteAPI(this, Constants.APP_KEY, accessToken).sendInvite(uid, jsonObject, mInviteRequestListener);
    } else {
        Toast.makeText(WBInviteAPIActivity.this, R.string.weibosdk_demo_access_token_is_empty,
                Toast.LENGTH_LONG).show();
    }
}

From source file:com.hphoto.server.ApiServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // get parameters from request
    request.setCharacterEncoding("UTF-8");

    // the query language
    String lang = request.getParameter("hl");
    String kind = request.getParameter("kind");
    String alt = request.getParameter("alt");
    String owner = request.getParameter("user");
    String feed = request.getParameter("feed");
    String albumid = request.getParameter("album");
    if (lang != null) {
        if (lang.indexOf('_') == -1) {
            //throw
        }//from  w  ww. j ava2s  .co m
        String language = lang.substring(0, lang.indexOf('_'));
        String count = lang.substring(lang.indexOf('_') + 1);
    }

    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        Document doc = factory.newDocumentBuilder().newDocument();

        Element rss = addNode(doc, doc, "rss");
        addAttribute(doc, rss, "version", "2.0");
        addAttribute(doc, rss, "xmlns:opensearch", (String) NS_MAP.get("opensearch"));
        addAttribute(doc, rss, "xmlns:atom", (String) NS_MAP.get("atom"));
        addAttribute(doc, rss, "xmlns:photo", (String) NS_MAP.get("photo"));
        addAttribute(doc, rss, "xmlns:media", (String) NS_MAP.get("media"));

        Element channel = addNode(doc, rss, "channel");

        if (kind.equals("album")) {
            addCategory(doc, channel, request);
        } else if (kind.equals("photo")) {
            addPhoto(doc, channel, request);
        } else {
            response.getOutputStream().println("Invalid paramenter.");
            return;
        }
        if (alt.equals("json")) {
            String value = null;
            try {
                value = org.json.XML.toJSONObject(doc.toString()).toString();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (value != null)
                response.getOutputStream().print(value);
            return;
        }
        // dump DOM tree

        DOMSource source = new DOMSource(doc);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.setOutputProperty("indent", "yes");
        StreamResult result = new StreamResult(response.getOutputStream());
        response.setContentType("text/xml");
        transformer.transform(source, result);

    } catch (javax.xml.parsers.ParserConfigurationException e) {
        throw new ServletException(e);
    } catch (javax.xml.transform.TransformerException e) {
        throw new ServletException(e);
    }

}

From source file:de.grobox.blitzmail.NotificationHandlerActivity.java

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

    Intent intent = getIntent();// w ww  .j a  v  a2  s .  c  o  m
    onNewIntent(intent);

    try {
        if (intent != null) {
            mMail = new JSONObject(intent.getStringExtra("mail"));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:asynctasks.AddTicketDataAsync.java

@Override
protected void onPostExecute(JSONObject json) {
    pDialog.cancel();/*from  w  w w.  j a  v  a 2 s .c o m*/
    int success;
    try {
        success = json.getInt("success");
        if (success == 1) {

            NewTicket frag = (NewTicket) fm.findFragmentByTag("New Ticket");
            frag.dismiss();

        } else {
            Toast.makeText(context, "ERROR IN SUBMISSION", Toast.LENGTH_SHORT).show();
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}