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.project.merauke.CustomItemizedOverlay.java

/**
 * extract JSON into usable data/*from  w  w  w. j a  v a2  s  .co  m*/
 * */
private ArrayList<CustomOverlayItem> processingJSON(String strJSON) {
    ArrayList<CustomOverlayItem> listPoints = new ArrayList<CustomOverlayItem>();
    try {
        JSONArray rowArray = new JSONArray(strJSON);
        // Log.d("JSON", "total: "+rowArray.length());

        int count = 0;
        JSONObject jsonElement = null;
        int posLat = 0;
        int posLng = 0;
        String name = "";
        String alamat = "";

        if (rowArray.length() != 0) {
            this.removeAll();// TODO robust impl.

            while (count < rowArray.length()) {

                jsonElement = rowArray.getJSONObject(count);
                posLat = (int) (Double.parseDouble(jsonElement.getString("lat")) * 1E6);
                posLng = (int) (Double.parseDouble(jsonElement.getString("lng")) * 1E6);
                name = jsonElement.getString("namalokasi");
                alamat = jsonElement.getString("alamat");

                listPoints.add(new CustomOverlayItem(new GeoPoint(posLat, posLng), name, alamat,
                        "http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg"));

                count++;
            }
            Log.d("JSON", "loading data finish");
        } else {
            Log.d("JSON", "EMPTY");
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return listPoints;
}

From source file:br.unicamp.cst.behavior.bn.Behavior.java

/**
 * @return the actionsSet/*w  w  w.  ja va2s.c om*/
 */
public String getActionList()//TODO a simpler version of this might be interesting
{
    //      return actionList;
    try {
        JSONArray teste = new JSONArray(jsonActionList.toString());

    } catch (JSONException e) {

        e.printStackTrace();
    }

    return jsonActionList.toString();
}

From source file:br.unicamp.cst.behavior.bn.Behavior.java

/**
 *  Checks if there is a current behavior proposition in working storage that is using the resources this behavior needs
 * @return if there is conflict of resources
 *//*from   w  w w  .  j  a v  a 2  s . c o  m*/
private boolean resourceConflict() {//TODO must develop this idea further
    boolean resourceConflict = false;
    ArrayList<MemoryObject> allOfType = new ArrayList<MemoryObject>();

    if (ws != null)
        allOfType.addAll(ws.getAllOfType("BEHAVIOR_PROPOSITION"));

    ArrayList<String> usedResources = new ArrayList<String>();

    if (allOfType != null) {

        for (MemoryObject bp : allOfType) {
            try {
                JSONObject jsonBp = new JSONObject(bp.getI());
                //System.out.println("=======> bp.getInfo(): "+bp.getInfo());
                boolean performed = jsonBp.getBoolean("PERFORMED");
                if (!performed) {//otherwise it is not consuming those resources

                    JSONArray resourceList = jsonBp.getJSONArray("RESOURCELIST");

                    for (int i = 0; i < resourceList.length(); i++) {
                        usedResources.add(resourceList.getString(i));
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
    //      System.out.println("%%% usedResources: "+usedResources);
    //      System.out.println("%%% getResourceList: "+getResourceList());
    int sizeBefore = usedResources.size();
    usedResources.removeAll(this.getResourceList());
    int sizeLater = usedResources.size();

    if (sizeLater != sizeBefore) {
        resourceConflict = true;
        //         System.out.println("%%%%%%%%%%%%%%%%%%%%% There was a conflict here");
    }

    return resourceConflict;
}

From source file:br.unicamp.cst.behavior.bn.Behavior.java

/**
 * @param action/*w  w  w.j a v  a2 s. c o  m*/
 *           the action to be added to actionSet
 */
public void addAction(String action) {
    this.actionList.add(action);
    String pNumber;
    String[] actionDecomposition = action.split(" ");
    JSONObject jsonAction = new JSONObject();
    try {
        if (!this.resourceList.contains(actionDecomposition[0])) {
            this.resourceList.add(actionDecomposition[0]); //Stores this resource in this behavior's resource list
        }

        jsonAction.put("RESOURCE", actionDecomposition[0]);
        jsonAction.put("ACTION", actionDecomposition[1]);
        for (int i = 2; i < actionDecomposition.length; i++) {
            pNumber = "P" + String.valueOf(i - 1);
            jsonAction.put(pNumber, actionDecomposition[i]);
        }

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

    this.jsonActionList.put(jsonAction);
    //      System.out.println("---JSON ACTION: "+jsonAction);
}

From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java

private void onFlowProcess(final String networkId, final Flow flow, String action) {
    seqNo = SEQNO_PREFIX + mf.requestNoToString();
    logger.info(seqNo + "\t" + "onFlowProcess Strat");

    NetworkInterface networkIf = networkInterfaces().get(networkId);
    BasicFlow targetFlow = getFlow(networkIf, flow.getFlowId());

    logger.debug(seqNo + "\t" + "Status:" + flow.getStatus());
    targetFlow.setStatus(FlowObject.FlowStatus.ESTABLISHING.toString());

    try {/*from  w w  w.ja  va  2s . c  o  m*/
        flowMessageManager(networkIf, networkId, action, targetFlow, seqNo);
    } catch (JSONException e) {
        logger.error(seqNo + "\t" + "get JSONException.");
        e.printStackTrace();
        return;
    } catch (IOException e) {
        logger.error(seqNo + "\t" + "get IOException.");
        e.printStackTrace();
        return;
    } catch (Exception e) {
        logger.error(seqNo + "\t" + "get Exception: " + e.getMessage());
        e.printStackTrace();
        return;
    }
    logger.info(seqNo + "\t" + "onFlowProcess End");
}

From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java

@Override
protected void onFlowDelete(final String networkId, final Flow flow) {
    seqNo = SEQNO_PREFIX + mf.requestNoToString();
    logger.info(seqNo + "\t" + "onFlowDelete Strat");
    logger.debug("network component ID : " + networkId);
    if (!onFlowDeletePre(networkId, flow)) {
        return;//from   ww  w.  ja va2 s. c  o  m
    }
    statusLog(flow);

    NetworkInterface networkIf = networkInterfaces().get(networkId);
    Flow targetFlow = flow;
    if (targetFlow.getStatus().equals(FlowObject.FlowStatus.ESTABLISHED.toString())
            && targetFlow.getEnabled()) {
        try {
            deleteFlow(networkIf, networkId, flow, seqNo);
        } catch (JSONException e) {
            logger.error(seqNo + "\t" + "get JSONException.");
            e.printStackTrace();
            statusLog(flow);
            return;
        } catch (IOException e) {
            logger.error(seqNo + "\t" + "get IOException.");
            e.printStackTrace();
            statusLog(flow);
            return;
        }
    }
    statusLog(flow);
    logger.info(seqNo + "\t" + "onFlowDelete End");
}

From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java

private void onLinkProcess(final String networkId, final Link link, String action) {
    seqNo = SEQNO_PREFIX + mf.requestNoToString();
    logger.info(seqNo + "\t" + "onLinkProcess Strat");
    logger.debug(seqNo + "\t" + "Link " + AttrElements.ESTABLISHMENT_STATUS + ":"
            + link.getAttribute(AttrElements.ESTABLISHMENT_STATUS));
    logger.debug(seqNo + "\t" + "action : " + action);

    NetworkInterface networkIf = networkInterfaces().get(networkId);

    if (!link.getAttribute(AttrElements.ESTABLISHMENT_STATUS)
            .equals(FlowObject.FlowStatus.ESTABLISHED.toString())) {
        logger.debug(seqNo + "\t" + "Link not established :" + link.getId());
        return;//from ww w.j a  v a2 s  .  c o m
    }

    try {
        linkMessageManager(networkIf, networkId, action, link, seqNo);
    } catch (JSONException e) {
        logger.error(seqNo + "\t" + "get JSONException.");
        e.printStackTrace();
        return;
    } catch (IOException e) {
        logger.error(seqNo + "\t" + "get IOException.");
        e.printStackTrace();
        return;
    }
    logger.info(seqNo + "\t" + "onLinkProcess End");
}

From source file:org.uiautomation.ios.server.servlet.IOSServlet.java

private Response getResponse(WebDriverLikeRequest request) {
    long start = System.currentTimeMillis();
    String command = "";
    WebDriverLikeCommand wdlc = null;/*from w  w  w. ja v a 2s  .c  om*/
    try {
        wdlc = request.getGenericCommand();
        Handler h = CommandMapping.get(wdlc).createHandler(getDriver(), request);
        command = wdlc.method() + "\t " + wdlc.path();
        return h.handleAndRunDecorators();
    } catch (WebDriverException we) {
        Response response = new Response();
        if (wdlc.isSessionLess()) {
            response.setSessionId("");
        } else {
            response.setSessionId(request.getSession());
        }

        response.setStatus(errorCodes.toStatusCode(we));

        try {
            JSONObject o = serializeException(we);
            response.setValue(o);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return response;
    } catch (Exception e) {
        throw new WebDriverException("bug." + e.getMessage(), e);
    } finally {
        String message = ((System.currentTimeMillis() - start) + "ms.\t" + command);
        log.info(message);
    }
}

From source file:nl.hnogames.domoticz.Domoticz.EventsXmlParser.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<EventXmlInfo> mVars = new ArrayList<>();

        if (jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject row = jsonArray.getJSONObject(i);
                mVars.add(new EventXmlInfo(row));
            }
        }

        if (mVars == null || mVars.size() <= 0)
            onError(new NullPointerException("No Event Details found in Domoticz."));
        else
            varsReceiver.onReceiveEventXml(mVars);

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

From source file:com.example.karspoolingapp.RouteByHitchhikerCar.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.routebyhitchhiker);

    Intent intent = getIntent();/*  w  ww .  j a  v a  2  s.c o m*/
    Bundle bundle = intent.getExtras();
    new_license_number = bundle.getString("pre_end_point");
    //session_username = session.getUsername();
    System.out.println("nayaaa licnse number" + new_license_number);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    // code for dynamic radio button generation
    final RadioButton[] rb = new RadioButton[100];
    rl = (RelativeLayout) findViewById(R.id.rl);
    rg = new RadioGroup(this);

    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("car_number", new_license_number));
    System.out.println(params);
    json = jsonParser.makeHttpRequest(READ_COMMENTS_URL2, "POST", params);
    params.clear();
    System.out.println(json);

    try {
        jsonTripDetails = json.getJSONArray("route");
        System.out.println(jsonTripDetails);
        int k = jsonTripDetails.length();
        if (k > 0) {
            for (int i = 0; i < jsonTripDetails.length(); i++) {
                JSONObject c = jsonTripDetails.getJSONObject(i);

                String parent_username_str = c.getString("username");
                String route = c.getString("route");
                String timing = c.getString("timing");
                String seating = c.getString("seating_capacity");
                rb[i] = new RadioButton(this);
                rg.addView(rb[i]);
                rb[i].setText(parent_username_str + "," + route + "," + timing + "," + seating);
                params.clear();

            }
            rl.addView(rg);
            rl.setPadding(50, 50, 50, 50);
        } else {
            Toast.makeText(RouteByHitchhikerCar.this, "No Trip available on these routes", Toast.LENGTH_LONG)
                    .show();
        }

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

    }

    addListenerOnButton();

}