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:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java

/** Process the QueryManager request and sends the response back to the client
 * @param//from   ww  w. j av  a 2 s.c o  m
 *
 */
void processGetRequest() throws IOException, RegistryException, InvalidRequestException, UnimplementedException,
        ObjectNotFoundException {
    String method = request.getParameter("method");
    String id = request.getParameter("param-id");
    String lid = request.getParameter("param-lid");
    String versionName = request.getParameter("param-versionName");
    @SuppressWarnings("unused")
    String flavor = request.getParameter("flavor");

    if ((method == null) || method.equals("")) {
        throw new InvalidRequestException(
                ServerResourceBundle.getInstance().getString("message.methodCannotBeNull"));
    } else if (method.equalsIgnoreCase("getRegistryObject")) {
        try {
            response.setContentType("text/xml; charset=UTF-8");

            String queryString = getQueryStringForFindByIdLidVersion(id, lid, versionName);
            List<RegistryObjectType> results = submitQueryAs(queryString, currentUser);
            if (results.isEmpty()) {
                throw new ObjectNotFoundException(getNotFoundExceptionMsg(id, lid, versionName));
            } else {
                if (results.size() > 1) {
                    writeDirectoryListing(results);
                } else {
                    RegistryObjectType ebRegistryObjectType = results.get(0);
                    writeRegistryObject(ebRegistryObjectType);
                }
            }
        } catch (NullPointerException e) {
            log.error(e.toString(), e);
            throw new RegistryException(
                    it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e));
        }
    } else if (method.equalsIgnoreCase("getRepositoryItem")) {
        try {
            String queryString = getQueryStringForFindByIdLidVersion(id, lid, versionName);
            List<RegistryObjectType> results = submitQueryAs(queryString, currentUser);
            if (results.isEmpty()) {
                throw new ObjectNotFoundException(getNotFoundExceptionMsg(id, lid, versionName));
            } else {
                //                    RegistryObjectType ro = (RegistryObjectType)results.get(0);
                // take ComplexType from Element
                //RegistryObjectType ebRegistryObjectType = ((JAXBElement<RegistryObjectType>)(results.get(0))).getValue();
                RegistryObjectType ebRegistryObjectType = results.get(0);

                // check the first ComplexType in result
                if (!(ebRegistryObjectType instanceof ExtrinsicObjectType)) {
                    //return the error code
                    throw new InvalidRequestException(ServerResourceBundle.getInstance().getString(
                            "message.expectedExtrinsicObjectNotFound",
                            new Object[] { ebRegistryObjectType.getClass() }));
                }

                if (results.size() > 1) {
                    writeDirectoryListing(results);
                } else {
                    ExtrinsicObjectType ebExtrinsicObjectType = (ExtrinsicObjectType) ebRegistryObjectType;
                    writeRepositoryItem(ebExtrinsicObjectType);
                }
            }
        } catch (NullPointerException e) {
            log.error(e.toString(), e);
            throw new RegistryException(
                    it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e));
        }
    } else if (method.equalsIgnoreCase("submitAdhocQuery")) {
        try {
            String startIndex = request.getParameter("startIndex");
            if (startIndex == null) {
                startIndex = "0";
            }

            String maxResults = request.getParameter("maxResults");
            if (maxResults == null) {
                maxResults = "-1";
            }

            String queryId = request.getParameter("queryId");
            if (queryId == null) {
                queryId = "urn:freebxml:registry:query:BusinessQuery";
            }

            //Create and populate queryParamsMap from request params map
            Map<String, String> queryParams = new HashMap<String, String>();

            Iterator<String> iter = request.getParameterMap().keySet().iterator();
            while (iter.hasNext()) {
                Object obj = iter.next();
                if (obj instanceof String) {
                    String paramName = (String) obj;

                    //Only use params whose names begin with '$' char
                    if (paramName.charAt(0) == '$') {
                        String paramValue = request.getParameter(paramName);
                        queryParams.put(paramName, paramValue);
                    }
                }
            }

            ServerRequestContext context = new ServerRequestContext(
                    "QueryManagerURLHandler.processGetRequest.submitAdhocQuery", null);
            List<IdentifiableType> ebIdentifiableTypeResultList = invokeParameterizedQuery(context, queryId,
                    queryParams, currentUser, Integer.parseInt(startIndex), Integer.parseInt(maxResults));
            String getRepositoryItem = request.getParameter("getRepositoryItem");
            if ((getRepositoryItem != null)
                    && ((getRepositoryItem.equalsIgnoreCase("true")) || (getRepositoryItem.equals("1")))) {
                writeRepositoryItemList(ebIdentifiableTypeResultList);
            } else {
                writeRegistryObjectList(ebIdentifiableTypeResultList);
            }
        } catch (NullPointerException e) {
            log.error(e.toString(), e);
            throw new RegistryException(
                    it.cnr.icar.eric.server.common.Utility.getInstance().getStackTraceFromThrowable(e));
        }
    } else if (method.equalsIgnoreCase("newUUID")) {
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        UUIDFactory uuidFac = UUIDFactory.getInstance();
        out.print(uuidFac.newUUID().toString());
        out.close();
    } else {
        //return the error code
        throw new InvalidRequestException(
                ServerResourceBundle.getInstance().getString("message.unknownMethod", new Object[] { method }));
    }
}

From source file:com.frostwire.search.youtube.jd.Request.java

/**
 * DO NEVER call this method directly... use browser.connect
 *//*w  w w .j av  a  2 s. c  o m*/
protected Request connect() throws IOException {
    try {
        this.openConnection();
        this.postRequest();
        /*
         * we connect to inputstream to make sure the response headers are getting parsed first
         */
        this.httpConnection.finalizeConnect();
        try {
            this.collectCookiesFromConnection();
        } catch (final NullPointerException e) {
            throw new IOException("Malformed url?" + e.toString());
        }
    } finally {
        this.requested = true;
    }
    return this;
}

From source file:app.com.vaipo.ContactsFragment.java

private void setUpFirebaseListner(final Context ctx) {
    myFirebaseRef = new Firebase("https://vaipo.firebaseio.com/" + LINK + "/" + appState.getID());
    myFirebaseRef.addValueEventListener(new ValueEventListener() {
        @Override//from  www . j a v a  2 s  . c  om
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.d(TAG, "There are " + dataSnapshot.getChildrenCount() + " values @ " + myFirebaseRef);
            String newSessionId = "-1", newToken = "-1", newApiKey = "-1";
            boolean peerAutoDiscover = false;

            DialMsg dialMsg = null;
            try {
                dialMsg = dataSnapshot.getValue(DialMsg.class);
            } catch (NullPointerException e) {
                return;
            } catch (Exception e) {
                Log.d(TAG, "Oops error ! " + e.getMessage() + e.toString());
                return;
            }
            if (dialMsg == null)
                return;

            if (dialMsg.getState() == DialMsg.END) {
                if (contactEditText != null)
                    contactEditText.setText("");
                Utils.endVaipoCall(ctx);
            } else {
                newSessionId = dialMsg.getSessionId();
                newToken = dialMsg.getToken();
                newApiKey = dialMsg.getApikey();
                peerAutoDiscover = dialMsg.getPeerautodiscover();

                // TBD: Fix this hack!!
                boolean response = dialMsg.getResponse();
                if (response)
                    Utils.sendUserResponse(ctx, response);
            }

            if (!newSessionId.equalsIgnoreCase("-1") && !newToken.equalsIgnoreCase("-1")
                    && !newApiKey.equalsIgnoreCase("-1")) {

                Intent i = new Intent(ctx, BubbleVideoView.class);
                i.putExtra("sessionId", newSessionId);
                i.putExtra("token", newToken);
                i.putExtra("apikey", newApiKey);
                i.putExtra("peerautodiscover", peerAutoDiscover);

                //if (ctx != null)
                //    ctx.startService(i);
                if (newApiKey.equals(OpenTokConfig.API_KEY) && newSessionId.equals(OpenTokConfig.SESSION_ID)
                        && newToken.equals(OpenTokConfig.TOKEN)) {
                    return;
                }
                OpenTokConfig.API_KEY = newApiKey;
                OpenTokConfig.SESSION_ID = newSessionId;
                OpenTokConfig.TOKEN = newToken;

                Utils.startUI(ctx);
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}

From source file:org.apache.gora.dynamodb.store.DynamoDBNativeStore.java

/**
 * Puts an object identified by a key/*  w w w  . j  av a 2s  .  com*/
 *
 * @param key
 * @param obj
 */
@Override
public void put(K key, T obj) {
    try {
        Object hashKey = getHashKey(key, obj);
        Object rangeKey = getRangeKey(key, obj);
        if (hashKey != null) {
            DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBStoreHandler.getDynamoDbClient());
            if (rangeKey != null) {
                mapper.load(persistentClass, hashKey, rangeKey);
            } else {
                mapper.load(persistentClass, hashKey);
            }
            mapper.save(obj);
        } else
            throw new GoraException("No HashKey found in Key nor in Object.");
    } catch (NullPointerException npe) {
        LOG.error("Error while putting an item. " + npe.toString());
        throw new NullArgumentException(npe.getMessage());
    } catch (Exception e) {
        LOG.error("Error while putting an item. " + obj.toString());
        throw new RuntimeException(e);
    }
}

From source file:displayStructureAsPDFTable.java

public void drawStructure(IAtomContainer mol, int cnt) {

    // do aromaticity detection
    try {/*www.  jav  a2 s .c o m*/
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
    } catch (CDKException cdke) {
        cdke.printStackTrace();
    }
    mol = addHeteroHydrogens(mol);
    r2dm = new Renderer2DModel();
    renderer = new Renderer2D(r2dm);
    Dimension screenSize = new Dimension(this.width, this.height);
    setPreferredSize(screenSize);
    r2dm.setBackgroundDimension(screenSize); // make sure it is synched with the JPanel size
    setBackground(r2dm.getBackColor());

    try {
        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        sdg.setMolecule((IMolecule) mol);
        sdg.generateCoordinates();
        this.mol = sdg.getMolecule();

        r2dm.setDrawNumbers(false);
        r2dm.setUseAntiAliasing(true);
        r2dm.setColorAtomsByType(doColor);
        r2dm.setShowAromaticity(true);
        r2dm.setShowAromaticityInCDKStyle(false);
        r2dm.setShowReactionBoxes(false);
        r2dm.setKekuleStructure(false);
        r2dm.setShowExplicitHydrogens(withH);
        r2dm.setShowImplicitHydrogens(true);
        GeometryTools.translateAllPositive(this.mol);
        GeometryTools.scaleMolecule(this.mol, getPreferredSize(), this.scale);
        GeometryTools.center(this.mol, getPreferredSize());
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    this.frame.getContentPane().add(this);
    this.frame.pack();

    String filename;
    if (cnt < 10)
        filename = this.odir + "/img00" + cnt + this.suffix;
    else if (cnt < 100)
        filename = this.odir + "/img0" + cnt + this.suffix;
    else
        filename = this.odir + "/img" + cnt + this.suffix;

    if (oformat.equalsIgnoreCase("png") || oformat.equalsIgnoreCase("jpeg")) {
        BufferedImage img;
        try {
            img = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_RGB);
            //                img = (BufferedImage) createImage(this.getSize().width, this.getSize().height);
            Graphics2D snapGraphics = (Graphics2D) img.getGraphics();
            this.paint(snapGraphics);
            File graphicsFile = new File(filename);
            ImageIO.write(img, oformat, graphicsFile);
        } catch (NullPointerException e) {
            System.out.println(e.toString());
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    } else if (oformat.equalsIgnoreCase("pdf")) {
        File file = new File(filename);
        Rectangle pageSize = new Rectangle(this.getSize().width, this.getSize().height);
        Document document = new Document(pageSize);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
            document.open();
            PdfContentByte cb = writer.getDirectContent();

            Image awtImage = createImage(this.getSize().width, this.getSize().height);
            Graphics snapGraphics = awtImage.getGraphics();
            paint(snapGraphics);

            com.lowagie.text.Image pdfImage = com.lowagie.text.Image.getInstance(awtImage, null);
            pdfImage.setAbsolutePosition(0, 0);
            cb.addImage(pdfImage);

        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    } else if (oformat.equalsIgnoreCase("svg")) {
        /*
             try {
        SVGWriter cow = new SVGWriter(new FileWriter(filename));
        if (cow != null) {
            cow.writeAtomContainer(mol);
            cow.close();
        }
             } catch (IOException ioe) {
        ioe.printStackTrace();
             } catch (CDKException cdke) {
        cdke.printStackTrace();
             }
        */
    }
}

From source file:net.java.dev.weblets.impl.faces.WebletsPhaseListener.java

protected void doBeforePhase(PhaseEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext external = context.getExternalContext();
    // test stuff remove me once verified
    /*/*from   www  .  j  a va2s . c  o m*/
       * req = utils.getRequestFromPath(external.getRequest(), "/weblets-demo/faces/weblets/demo$1.0/welcome.js");
       *
       * ServletContext ctx = (ServletContext) external.getContext(); String mime = ctx.getMimeType("/faces/weblets/demo$1.0/welcome.js");
       *
       * InputStream strm = utils.getResourceAsStream(req, mime); BufferedReader istrm = new BufferedReader(new InputStreamReader(strm)); try { String line =
       * ""; while ((line = istrm.readLine() ) != null) { System.out.println(line); } istrm.close();
       *
       * } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. }
       *
       *
       * req = utils.getRequestFromPath(external.getRequest(), "/faces/weblets/demo$1.0/welcome.js"); utils.getResourceAsStream(req, mime);
       *
       * req = utils.getRequestFromPath(external.getRequest(), "http://localhost:8080/weblets-demo/faces/weblets/demo$1.0/welcome.js");
       * utils.getResourceAsStream(req, mime);
       *
       * req = utils.getRequestFromPath(external.getRequest(), "/xxx/aa/demo$1.0/welcome.js"); utils.getResourceAsStream(req, mime);
       *
       *
       * req = utils.getRequestFromPath(external.getRequest(), "/xxx/aa/demo$1.0/booga.js"); Object strobj = utils.getResourceAsStream(req, mime);
       */
    WebletContainerImpl container = (WebletContainerImpl) WebletContainer.getInstance();
    String pathInfo = external.getRequestServletPath();
    if (pathInfo != null && external.getRequestPathInfo() != null)
        pathInfo += external.getRequestPathInfo();
    if (pathInfo == null && event.getPhaseId() == PhaseId.RESTORE_VIEW) {
        // we are in a portlet environment here, since we do not get an external path info
        // we skip this phase and renter after the restore view
        event.getFacesContext().getExternalContext().getRequestMap().put(WEBLETS_PHASE_LISTENER_ENTERED,
                Boolean.FALSE);
        return;
    }
    // special portlet treatment here
    // we move to later phases here to the apply request values
    // to become portlet compatible, unfortunately
    // we lose a little bit of performance then
    // but the determination of the pathInfo over
    // the view id is more neutral than over
    // the request servlet which is rundered null
    // in some portlet environments
    if (pathInfo == null)
        pathInfo = context.getViewRoot().getViewId();
    Matcher matcher = null;
    try {
        matcher = container.getPattern().matcher(pathInfo);
    } catch (NullPointerException ex) {
        Log log = LogFactory.getLog(this.getClass());
        log.error(
                "An error has occurred no pattern or matcher has been detected, this is probably a sign that the weblets context listener has not been started. please add following lines to your web.xml \n"
                        + " <listener>\n"
                        + "       <listener-class>net.java.dev.weblets.WebletsContextListener</listener-class>\n"
                        + " </listener>");
        log.error("Details of the original Error:" + ex.toString());
        return;
    }
    if (matcher.matches()) {
        Map requestHeaders = external.getRequestHeaderMap();
        String contextPath = external.getRequestContextPath();
        String requestURI = matcher.group(1);
        String ifModifiedHeader = (String) requestHeaders.get("If-Modified-Since");
        long ifModifiedSince = -1L;
        if (ifModifiedHeader != null) {
            try {
                DateFormat rfc1123 = new HttpDateFormat();
                Date parsed = rfc1123.parse(ifModifiedHeader);
                ifModifiedSince = parsed.getTime();
            } catch (ParseException e) {
                throw new FacesException(e);
            }
        }
        try {
            String[] parsed = container.parseWebletRequest(contextPath, requestURI, ifModifiedSince);
            if (parsed != null) {
                ServletContext servletContext = (ServletContext) external.getContext();
                ServletRequest httpRequest = (ServletRequest) external.getRequest();
                ServletResponse httpResponse = (ServletResponse) external.getResponse();
                String webletName = parsed[0];
                String webletPath = parsed[1];
                String webletPathInfo = parsed[2];
                WebletRequest webRequest = new WebletRequestImpl(webletName, webletPath, contextPath,
                        webletPathInfo, ifModifiedSince, httpRequest);
                String contentName = webRequest.getPathInfo();
                String contentTypeDefault = servletContext.getMimeType(contentName);
                WebletResponse webResponse = new WebletResponseImpl(contentTypeDefault, httpResponse);
                container.service(webRequest, webResponse);
                context.responseComplete();
            }
        } catch (IOException e) {
            throw new FacesException(e);
        }
    }
}

From source file:com.ijiaban.yinxiang.MainActivity.java

/**
 * Changes the color of the action bar and status bar
 * @param color ARGB Color to apply/*from  www.j  a  v  a2  s.  c om*/
 */
@SuppressLint("NewApi")
private void setColor(int color) {
    View mainView = findViewById(R.id.rootView);
    if (mainView == null) {
        Log.e("MainActivity:setColor()", "WARNING: Did not find root view.");
    } else {
        mainView.setBackgroundColor(color);
    }

    /*
    Set the action bar colour to the average colour of the generated image and
    the status bar colour for Android Version >= 5.0 accordingly.
    */
    try {
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
    } catch (NullPointerException nullError) {
        Log.e("MainActivity:generateImageTask()", nullError.toString());
    } catch (NoSuchMethodError methodError) {
        Log.e("MainActivity:generateImageTask()", methodError.toString());
    }

    Log.d("MainActivity:generateImageTask()", "Changing status bar & action bar colour.");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Get the window through a reference to the activity.
        Activity parent = (Activity) mContext;
        Window window = parent.getWindow();
        // Set the status bar colour of this window.
        int statusColor = ColorUtilities.getDarkenedColor(color);
        window.setStatusBarColor(statusColor);
    }
}

From source file:com.nikolak.weatherapp.ForecastIO.Forecast.java

public Boolean updateForecast(String lat, String lon, String lang) throws JSONException {
    JSONObject response;//from w ww.  jav a2  s . c om
    try {
        response = forecastAPI.getDefault(lat, lon, lang);
    } catch (NullPointerException e) {
        return false;
    }

    JSONObject currentlyJObject = response.getJSONObject("currently");
    this.currently.ConstructFromJson(currentlyJObject);

    try {
        JSONObject minutelyJObject = response.getJSONObject("minutely");
        if (minutelyJObject != null) {
            minutely.constructFromJson(minutelyJObject);
        } else {
            minutely = null;
        }
    } catch (JSONException e) {
        Log.d("Json", "Minutely not available");
    }
    try {
        JSONObject hourlyJObject = response.getJSONObject("hourly");
        this.hourly.constructFromJson(hourlyJObject);
    } catch (JSONException e) {
        Log.d("Hourly exception", e.toString());
    }

    JSONObject dailyObject = response.getJSONObject("daily");
    this.daily.constructFromJson(dailyObject);

    JSONObject flagsObject = response.getJSONObject("flags");
    this.flags.constructFromJson(flagsObject);
    return true;
}

From source file:se.lu.nateko.edca.BackboneSvc.java

/**
 * Set method to assign a ServerConnection object to be the currently active connection,
 * and tries to connect with a getCapabilities request.
 * @param srv The ServerConnection to be in use.
 *///w ww. ja va 2  s . c o m
public void setActiveServer(ServerConnection srv) {
    //      Log.d(TAG, "setActiveServer(ServerConnection) called.");
    try {
        Log.i(TAG, "New active server '" + srv.getAddress());
        mActiveServer = srv;
    } catch (NullPointerException e) {
        Log.w(TAG, e.toString());
        mActiveServer = null;
    }
}

From source file:net.longfalcon.newsj.TVRageService.java

private long getRageIdFromTraktResultsSafe(TraktResult traktResult) {
    try {//w w w  .j av  a2s  . com
        if (traktResult == null) {
            return -2;
        }

        TraktShowResult showResult = traktResult.getShowResult();

        if (showResult == null) {
            return -2;
        }

        TraktIdSet traktIdSet = showResult.getIds();

        if (traktIdSet == null) {
            return -2;
        }

        long rageId = traktIdSet.getTvrage();
        _log.info("found rage id: " + rageId);
        return rageId;
    } catch (NullPointerException e) {
        _log.error(e.toString(), e);
        return -2;
    }
}