Example usage for java.lang NullPointerException toString

List of usage examples for java.lang NullPointerException toString

Introduction

In this page you can find the example usage for java.lang NullPointerException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.red5.webapps.admin.Application.java

/**
 * Search through all the scopes in the given scope to a scope with the
 * given name/*from   www.j ava  2s  . c  o m*/
 * 
 * @param root
 * @param scopeName
 * @return IScope the requested scope
 */
private IScope getScopes(IScope root, String scopeName) {
    // log.info("Found scope "+root.getName());
    if (root.getName().equals(scopeName)) {
        return root;
    } else {
        if (root instanceof IScope) {
            Set<String> names = root.getScopeNames();
            for (String name : names) {
                try {
                    IScope parent = root.getScope(name);
                    IScope scope = getScopes(parent, scopeName);
                    if (scope != null) {
                        return scope;
                    }
                } catch (NullPointerException npe) {
                    log.debug(npe.toString());
                }
            }
        }
    }
    return null;
}

From source file:fragments.InfoListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setListAdapter();/*from  w w  w. j a  v  a 2  s .com*/

    mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mQuickReturnHeight = mQuickReturnView.getHeight();
            mListView.computeScrollY();
        }
    });

    mListView.setOnScrollListener(new OnScrollListener() {
        @SuppressLint("NewApi")
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mScrollY = 0;
            int translationY = 0;

            try {
                if (mListView.scrollYIsComputed()) {
                    mScrollY = mListView.getComputedScrollY();
                }
            } catch (NullPointerException ex) {
                Log.e(InfoListFragment.class.getSimpleName(), ex.toString());
            }

            int rawY = mScrollY;

            switch (mState) {
            case Constants.STATE_OFFSCREEN:
                if (rawY >= mMinRawY) {
                    mMinRawY = rawY;
                } else {
                    mState = Constants.STATE_RETURNING;
                }
                translationY = rawY;
                break;

            case Constants.STATE_ONSCREEN:
                if (rawY > mQuickReturnHeight) {
                    mState = Constants.STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                translationY = rawY;
                break;

            case Constants.STATE_RETURNING:

                translationY = (rawY - mMinRawY) + mQuickReturnHeight;

                System.out.println(translationY);
                if (translationY < 0) {
                    translationY = 0;
                    mMinRawY = rawY + mQuickReturnHeight;
                }

                if (rawY == 0) {
                    mState = Constants.STATE_ONSCREEN;
                    translationY = 0;
                }

                if (translationY > mQuickReturnHeight) {
                    mState = Constants.STATE_OFFSCREEN;
                    mMinRawY = rawY;
                }
                break;
            }

            /** this can be used if the build is below honeycomb **/
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                anim = new TranslateAnimation(0, 0, translationY, translationY);
                anim.setFillAfter(true);
                anim.setDuration(0);
                mQuickReturnView.startAnimation(anim);
            } else {
                mQuickReturnView.setTranslationY(translationY);
            }

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
}

From source file:org.red5.server.plugin.admin.AdminHandler.java

/**
 * Get all the scopes// w ww.j  a v  a2  s  .c om
 * 
 * @param scopeName
 * @return HashMap containing all the scopes
 */
public HashMap<Integer, String> getScopes(String scopeName) {
    IScope root = ScopeUtils.findRoot(scope);
    IScope scopeObj = root.getScope(scopeName);
    scopes = new HashMap<Integer, String>();
    try {
        getRooms(scopeObj, 0);
    } catch (NullPointerException npe) {
        log.debug(npe.toString());
    }
    return scopes;
}

From source file:org.red5.server.plugin.admin.AdminHandler.java

/**
 * Get all the scopes/*from w w  w.j  a v a  2s  . c om*/
 * 
 * @param root
 *            the scope to from
 * @param depth
 *            scope depth
 */
public void getRooms(IScope root, int depth) {
    Iterator<String> iter = (Iterator<String>) root.getScopeNames();
    String indent = "";
    for (int i = 0; i < depth; i++) {
        indent += " ";
    }
    while (iter.hasNext()) {
        String name = iter.next();
        String name2 = name.substring(1, name.length());
        try {
            IScope parent = root.getScope(name2);
            // parent
            getRooms(parent, depth + 1);
            scopes.put(scopeId, indent + name2);
            scopeId++;
            // log.info("Found scope: "+name2);
        } catch (NullPointerException npe) {
            log.debug(npe.toString());
        }
    }
}

From source file:org.red5.server.plugin.admin.AdminHandler.java

/**
 * Search through all the scopes in the given scope to a scope with the
 * given name//from w ww . j a  v  a2s .  c o m
 * 
 * @param root
 * @param scopeName
 * @return IScope the requested scope
 */
private IScope getScopes(IScope root, String scopeName) {
    // log.info("Found scope "+root.getName());
    if (root.getName().equals(scopeName)) {
        return root;
    } else {
        Iterator<String> iter = (Iterator<String>) root.getScopeNames();
        while (iter.hasNext()) {
            String name = iter.next();
            String name2 = name.substring(1, name.length());
            try {
                IScope parent = root.getScope(name2);
                IScope scope = getScopes(parent, scopeName);
                if (scope != null) {
                    return scope;
                }
            } catch (NullPointerException npe) {
                log.debug(npe.toString());
            }
        }
    }
    return null;
}

From source file:de.teambluebaer.patientix.helper.RestfulHelper.java

/**
 * Method which post data to the server//from  www . j a  v  a 2 s. c o m
 *
 * @param restMethod Method which to be set
 * @param pM         Parameter-Map for the post request
 */
public synchronized void postDataToServer(final String restMethod, final ArrayList<NameValuePair> pM) {
    if (DEBUG) {
        Log.d("pm", pM.toArray().toString());
        Log.d("restMethod", restMethod);
    }
    response = null;
    client = createHttpClient();

    try {
        if (DEBUG) {
            Log.d("POST_URL: ", POST_URL);
        }
        post = new HttpPost(POST_URL);
        post.setEntity(new UrlEncodedFormEntity(pM));
        Log.d("Http", new UrlEncodedFormEntity(pM).toString());
        response = client.execute(post);
        responseArray = IOUtils.toByteArray(response.getEntity().getContent());
        responseString = getStringFromInputStream(responseArray);
        responseCode = response.getStatusLine().getStatusCode();
    } catch (NullPointerException e) {
        e.printStackTrace();
        Log.d("Fehler: ", String.valueOf(true));
        Log.d("Fehler", e.toString());

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Log.d("Fehler: ", String.valueOf(true));
        Log.d("Fehler", e.toString());

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Log.d("Fehler: ", String.valueOf(true));
        Log.d("Fehler", e.toString());

    } catch (IOException e) {
        e.printStackTrace();
        responseCode = 503;
        Log.d("Fehler: ", String.valueOf(true));
        Log.d("Fehler", e.toString());

    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.DELETE, produces = "application/json")
public CustomResponseMessage deleteBarang(@RequestHeader String apiKey,
        @RequestBody BarangRequest barangRequest) {
    try {/*  w  w  w .ja  v a 2  s  .  c om*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Delete");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);
        barangService.deleteBarang(barangRequest.getId());
        return new CustomResponseMessage(HttpStatus.CREATED, "Delete Barang successfull");
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java

@RequestMapping(method = RequestMethod.PUT, produces = "application/json")
public CustomResponseMessage updateBarang(@RequestHeader String apiKey,
        @RequestBody BarangRequest barangRequest) {
    try {/* w w  w . j a  v  a 2  s  .  co m*/
        if (!authApiKey(apiKey)) {
            return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication");
        }

        if (checkRateLimit(RATE_LIMIT, apiKey)) {
            return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED,
                    "Please wait a while, you have reached your rate limit");
        }

        LogRequest temp = DependencyFactory.createLog(apiKey, "Put");

        Log log = new Log();
        log.setApiKey(temp.getApiKey());
        log.setStatus(temp.getStatus());
        log.setTimeRequest(temp.getTime_request());
        logService.addLog(log);

        Barang barang = barangService.getBarang(barangRequest.getId());
        barang.setJumlah(barangRequest.getJumlahBarang());
        barang.setKategoriBarang(kategoriBarangService.getKategoriBarang(barangRequest.getIdKategoriBarang()));
        barang.setNama(barangRequest.getNama());
        barang.setStatus(barangRequest.getStatus());
        barang.setUrl_image(barangRequest.getUrl_image());
        barang.setUser(userService.getUser(barangRequest.getIdUserPemilik()));
        barangService.updateBarang(barang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Update Barang Successfull");
    } catch (NullPointerException ex) {
        return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:com.yahoo.validatar.execution.rest.JSON.java

/**
 * Makes the request and returns the String response using the given client, request and query.
 *
 * @param client The HttpClient to use.//from  w  w w .j  a va 2  s . c o m
 * @param request The HttpUriRequest to make.
 * @param query The Query object being run.
 * @return The String response of the call, null if exception (query is failed).
 */
String makeRequest(HttpClient client, HttpUriRequest request, Query query) {
    try {
        log.info("{}ing to {} with headers {}", request.getMethod(), request.getURI(), request.getAllHeaders());
        HttpResponse response = client.execute(request);
        StatusLine line = response.getStatusLine();
        log.info("Received {}: {} with headers {}", line.getStatusCode(), line.getReasonPhrase(),
                response.getAllHeaders());
        String data = EntityUtils.toString(response.getEntity());
        log.info("Received response as string {}", data);
        return data;
    } catch (IOException ioe) {
        log.error("Could not execute request", ioe);
        query.setFailure("Could not execute request");
        query.addMessage(ioe.toString());
    } catch (NullPointerException npe) {
        log.error("Received no response", npe);
        query.setFailure("Received no response");
        query.addMessage(npe.toString());
    }
    return null;
}

From source file:com.opentransport.rdfmapper.nmbs.ScrapeTrip.java

private GtfsRealtime.FeedEntity.Builder parseJson(int identifier, String fileName, boolean canceled,
        String trainName) {/*from   ww  w. j a v a  2s  .c om*/
    GtfsRealtime.FeedEntity.Builder feedEntity = GtfsRealtime.FeedEntity.newBuilder();
    feedEntity.setId(Integer.toString(identifier));
    feedEntity.setIsDeleted(false);

    //Data that doesnt Update
    GtfsRealtime.TripUpdate.Builder tripUpdate = GtfsRealtime.TripUpdate.newBuilder();
    GtfsRealtime.VehicleDescriptor.Builder vehicleDescription = GtfsRealtime.VehicleDescriptor.newBuilder();
    GtfsRealtime.TripDescriptor.Builder tripDescription = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = GtfsRealtime.TripUpdate.StopTimeUpdate
            .newBuilder();

    //Each StopTime Update contains StopTimeEvents with the stop Arrival and Departure Time 
    GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeArrival = GtfsRealtime.TripUpdate.StopTimeEvent
            .newBuilder();
    GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeDeparture = GtfsRealtime.TripUpdate.StopTimeEvent
            .newBuilder();

    JSONParser parser = new JSONParser();
    try {
        FileReader fr = new FileReader(fileName);
        JSONObject json = (JSONObject) parser.parse(fr);
        String trainId = (String) json.get("vehicle");
        //Setting the VehicleData
        String routeId = trainName;
        vehicleDescription.setId(routeId);
        vehicleDescription.setLicensePlate(trainId);

        //Handling Departure Date
        String unixSeconds = (String) json.get("timestamp");
        Long unixSec = Long.parseLong(unixSeconds);

        Date date = new Date(unixSec * 1000L); // *1000 is to convert seconds to milliseconds
        SimpleDateFormat sdfStartDate = new SimpleDateFormat("yyyyMMdd"); // the format of your date
        sdfStartDate.setTimeZone(TimeZone.getTimeZone("GMT+2")); // give a timezone reference for formating
        SimpleDateFormat sdfStartTimeHour = new SimpleDateFormat("HH:mm:ss");

        String formattedDepartureDate = sdfStartDate.format(date);
        // String formattedDepartureHour = sdfStartTimeHour.format(date);

        // Setting the Trip Description
        // tripDescription.setStartTime(formattedDepartureHour);
        //YYYYMMDD format
        tripDescription.setStartDate(formattedDepartureDate);
        tripDescription.setRouteId(routeId);

        String tripId = tr.getTripIdFromRouteId(routeId, cdr);
        tripDescription.setTripId(tripId);

        //Get Information about stops
        JSONObject rootStop = (JSONObject) json.get("stops");
        JSONArray stops = (JSONArray) rootStop.get("stop");
        String arrivalDelay = "0";
        String departureDelay = "0";
        int maxDelay = 0;

        String firstStopName = "";
        String lastStopName = "";

        boolean wholeTripCanceled = true; // True when all stoptimes since now are canceled

        for (int i = 0; i < stops.size(); i++) {
            //Information about the stops
            JSONObject stop = (JSONObject) stops.get(i);
            // String stopSeq = (String) stop.get("id");

            stopTimeUpdate.setStopSequence(i);
            try {

                JSONObject station = (JSONObject) stop.get("stationinfo");
                // tripDescription.setRouteId((String) station.get("@id"));

                String stopId = (String) station.get("id");
                stopId = stopId.replaceFirst("[^0-9]+", "") + ":";
                stopId = stopId.substring(2); // remove first '00'
                if (!stop.get("platform").equals("") && !stop.get("platform").equals("?")) {
                    stopId += stop.get("platform");
                } else {
                    stopId += "0";
                }

                stopTimeUpdate.setStopId(stopId);

                // Constructing route long name from first and last stop
                if (i == 0) {
                    firstStopName = (String) station.get("standardname");
                } else if (i == stops.size() - 1) {
                    lastStopName = (String) station.get("standardname");
                }

            } catch (Exception e) {
                errorWriter.writeError(e.toString() + fileName);
                System.out.println(fileName);
                System.out.println(e);
            }

            // delays
            arrivalDelay = (String) stop.get("arrivalDelay");
            departureDelay = (String) stop.get("departureDelay");

            int arrivalDelayInt = Integer.parseInt(arrivalDelay);
            int departureDelayInt = Integer.parseInt(departureDelay);

            if (maxDelay < arrivalDelayInt) {
                maxDelay = arrivalDelayInt;
            }
            if (maxDelay < departureDelayInt) {
                maxDelay = departureDelayInt;
            }

            long now = System.currentTimeMillis();

            //Calculate arrival times
            long scheduledArrivalTimeUnixSeconds = Long.parseLong((String) stop.get("scheduledArrivalTime"));
            java.util.Date scheduledArrivalTime = new java.util.Date(
                    (long) scheduledArrivalTimeUnixSeconds * 1000);
            // add arrivalDelay to get real arrival time
            long arrivalTimeMillis = (DateUtils.addSeconds(scheduledArrivalTime, arrivalDelayInt)).getTime();

            //Calculate departure times
            long scheduledDepartureTimeUnixSeconds = Long
                    .parseLong((String) stop.get("scheduledDepartureTime"));
            java.util.Date scheduledDepartureTime = new java.util.Date(
                    (long) scheduledDepartureTimeUnixSeconds * 1000);
            // add departureDelay to get real departure time
            long departureTimeMillis = (DateUtils.addSeconds(scheduledDepartureTime, departureDelayInt))
                    .getTime();

            // If stoptime is (partially) canceled
            String isCanceled = (String) stop.get("canceled");
            if (!isCanceled.equals("0")) {
                // Set ScheduleRelationship of stoptime to SKIPPED
                stopTimeUpdate.setScheduleRelationship(
                        GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED);
            } else {
                // If a current or future stoptime isn't canceled, the whole trip isn't canceled
                if (wholeTripCanceled && arrivalTimeMillis >= now) {
                    wholeTripCanceled = false;
                }
            }

            // Set Arrival in the object
            stopTimeArrival.setDelay(arrivalDelayInt);
            //    setTime takes parameter in seconds
            stopTimeArrival.setTime(arrivalTimeMillis / 1000);
            stopTimeUpdate.setArrival(stopTimeArrival);
            // Do the same for departure
            stopTimeDeparture.setDelay(Integer.parseInt(departureDelay));
            //    setTime takes parameter in seconds
            stopTimeDeparture.setTime(departureTimeMillis / 1000);
            stopTimeUpdate.setDeparture(stopTimeDeparture);
            tripUpdate.addStopTimeUpdate(stopTimeUpdate);
        }

        tripDescription.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
        if (wholeTripCanceled) {
            // Can be partially canceled
            tripDescription.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
        }

        String route_long_name = firstStopName + " - " + lastStopName;
        vehicleDescription.setLabel(route_long_name);
        tripUpdate.setTrip(tripDescription);
        tripUpdate.setVehicle(vehicleDescription);
        tripUpdate.setDelay(maxDelay);
        feedEntity.setTripUpdate(tripUpdate);

        fr.close();
    } catch (FileNotFoundException ex) {
        System.out.println(ex);
        errorWriter.writeError(ex.toString());

    } catch (IOException ex) {
        System.out.println("IO exception" + ex);

    } catch (ParseException ex) {
        System.out.println("Parse exception " + ex + " " + fileName);
    } catch (NullPointerException npe) {
        System.out.println(npe.toString());
    }

    return feedEntity;
}