Example usage for java.lang NullPointerException getLocalizedMessage

List of usage examples for java.lang NullPointerException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.swordlord.jalapeno.datacontainer.DataContainer.java

/**
 * Persist object context.//from   w  ww  .  ja va 2s .  co  m
 * 
 * @param oc the oc
 * 
 * @return true, if successful
 */
private boolean persistObjectContext(ObjectContext oc) {
    try {
        // disabling the context validation should only be used when you know what you do!
        if (getDisableValidation()) {
            DataContext context = (DataContext) oc;
            context.setValidatingObjectsOnCommit(false);
        }
        oc.commitChanges();
    } catch (ValidationException vex) {
        String strMessage = "";

        ValidationResult vr = vex.getValidationResult();
        if (vr.hasFailures()) {
            List<ValidationFailure> failures = vr.getFailures();
            if (failures.size() > 0) {
                Iterator<ValidationFailure> it = failures.iterator();
                while (it.hasNext()) {
                    ValidationFailure failure = it.next();
                    if (failure != null) {
                        addError(failure.getSource().toString(), failure.getDescription());

                        LOG.info(failure.getSource() + " - " + failure.getDescription());
                    }

                    if (failure instanceof BeanValidationFailure) {
                        BeanValidationFailure bvf = (BeanValidationFailure) failure;
                        strMessage += bvf.getSource() + " - " + bvf.getProperty() + " - " + bvf.getDescription()
                                + ".\n\r";
                        LOG.error(bvf.getSource() + " - " + bvf.getProperty() + " - " + bvf.getDescription());
                    }
                }
            }
        }

        String strError = "Persist crashed: " + vex.getMessage() + ": " + vex.getCause() + "\n\r" + strMessage;
        LOG.info(strError);

        strMessage = vex.getLocalizedMessage() + " - " + strMessage;

        Throwable cause = vex.getCause();
        if (cause != null) {
            strMessage += " - " + cause.getMessage();
        }

        addError("", strMessage);

        //ErrorDialog.reportError("validation: " + strMessage);
        return false;
    } catch (DeleteDenyException dde) {
        String strError = "Persist crashed: " + dde.getLocalizedMessage() + ": " + dde.getCause();
        LOG.error(strError);

        String strMessage = dde.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (FaultFailureException ffe) {
        String strError = "Persist crashed: " + ffe.getLocalizedMessage() + ": " + ffe.getCause();
        LOG.error(strError);

        String strMessage = ffe.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (CayenneRuntimeException cex) {
        String strError = "Persist crashed: " + cex.getMessage() + ": " + cex.getCause();
        LOG.error(strError);

        String strMessage = cex.getLocalizedMessage();

        addError("", strMessage);

        return false;
    } catch (NullPointerException e) {
        String strError = "Persist crashed: NullPointerException";
        LOG.error(strError);

        addError("", strError);
        LOG.debug(e.getMessage());

        return false;
    } catch (Exception e) {
        String strError = "Persist crashed: " + e.getLocalizedMessage() + ": " + e.getCause();
        LOG.error(strError);

        String strMessage = e.getLocalizedMessage();

        addError("", strMessage);

        return false;
    }

    return true;
}

From source file:org.catechis.Stats.java

private void addErrorToLog(java.lang.NullPointerException npe) {
    log.add("toString           : " + npe.toString());
    log.add("getMessage         : " + npe.getMessage());
    log.add("getLocalziedMessage:" + npe.getLocalizedMessage());
    Throwable throwup = npe.getCause();
    Throwable init_cause = npe.initCause(throwup);
    log.add("thowable.msg       :" + init_cause.toString());
    StackTraceElement[] ste = npe.getStackTrace();
    for (int j = 0; j < ste.length; j++) {
        log.add(j + " - " + ste[j].toString());
        if (j > 6) {
            log.add("  ...");
            break;
        }/*from   www.ja va2  s . c  o m*/
    }
}

From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java

@SuppressLint("NewApi")
public static List<JsonNode> getFoursquareAutocomplete(Address address, Context context, Location location) {

    double lat;/*from  w  w  w .  jav  a 2s. co m*/
    double lon;
    try {
        lat = location.getLatitude();
        lon = location.getLongitude();
    } catch (NullPointerException e) {
        lat = -1.0;
        lon = -1.0;
    }

    String urlString;
    List<JsonNode> list = null;
    try {
        String query = URLEncoder.encode(normalizeToAlphabet(address.street), "UTF-8");

        String near = null;
        if (address.zip != null && !address.zip.equals("")) {
            if (address.city != null && !address.city.equals("")) {
                near = address.zip + " " + address.city;
            } else {
                near = address.zip + ", Denmark";
            }
        } else {
            if (address.city != null && !address.city.equals("")) {
                near = address.city;
            }
        }

        if (near != null && !near.equals("")) {
            urlString = "https://api.foursquare.com/v2/venues/search?intent=browse&near="
                    + URLEncoder.encode(near, "UTF-8") + "&client_id=" + FOURSQUARE_ID + "&client_secret="
                    + FOURSQUARE_SECRET + "&query=" + URLEncoder.encode(query, "UTF-8") + "&v=20130301&radius="
                    + FOURSQUARE_SEARCH_RADIUS + "&limit=" + FOURSQUARE_LIMIT + "&categoryId="
                    + FOURSQUARE_CATEGORIES;
        } else {
            urlString = "https://api.foursquare.com/v2/venues/search?intent=browse&ll=" + lat + "," + lon
                    + "&client_id=" + FOURSQUARE_ID + "&client_secret=" + FOURSQUARE_SECRET + "&query="
                    + URLEncoder.encode(query, "UTF-8") + "&v=" + 20130301 + "&radius="
                    + FOURSQUARE_SEARCH_RADIUS + "&limit=" + FOURSQUARE_LIMIT + "&categoryId="
                    + FOURSQUARE_CATEGORIES;
        }

        JsonNode rootNode = performGET(urlString);

        if (rootNode != null && rootNode.has("response")) {
            if (rootNode.get("response").has("minivenues")) {
                list = Util.JsonNodeToList(rootNode.get("response").get("minivenues"));
            } else if (rootNode.get("response").has("venues")) {
                list = Util.JsonNodeToList(rootNode.get("response").get("venues"));
            }
        }

    } catch (UnsupportedEncodingException e) {
        LOG.e(e.getLocalizedMessage());
    }

    return list;
}

From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java

protected void updateLabel(String name) {

    try {/*w w  w . ja  va2  s .  co  m*/
        ImageIcon icon = new ImageIcon(img.getImage(name));
        Image image = icon.getImage(); // transform it
        Image newimg = image.getScaledInstance(90, 90, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
        icon = new ImageIcon(newimg); // transform it back
        Icons.setIcon(icon);
        Icons.setToolTipText("A drawing of a " + name.toLowerCase());
        Icons.setText(null);
    } catch (NullPointerException e) {

        if (!img.getMapImg().isEmpty()) {
            Icons.setText("Image not found");
            model.error(e.getLocalizedMessage());
        }
    }
    updateLogArea();
}

From source file:org.jboss.processFlow.knowledgeService.BaseKnowledgeSessionBean.java

/******************************************************************************
 * *************            WorkItemHandler Management               *********/

public String printWorkItemHandlers() {
    StringBuilder sBuilder = new StringBuilder("Programmatically Loaded Work Item Handlers :");
    for (String name : programmaticallyLoadedWorkItemHandlers.keySet()) {
        sBuilder.append("\n\t");
        sBuilder.append(name);/*w w  w  .j  av a 2 s.c om*/
        sBuilder.append(" : ");
        sBuilder.append(programmaticallyLoadedWorkItemHandlers.get(name));
    }
    sBuilder.append("\nWork Item Handlers loaded from drools session template:");
    SessionTemplate sTemplate = newSessionTemplate(null);
    if (sTemplate != null && (sTemplate.getWorkItemHandlers() != null)) {
        for (Map.Entry<?, ?> entry : sTemplate.getWorkItemHandlers().entrySet()) {
            Class wiClass = entry.getValue().getClass();
            sBuilder.append("\n\t");
            sBuilder.append(entry.getKey());
            sBuilder.append(" : ");
            sBuilder.append(wiClass.getClass());
        }
    } else {
        sBuilder.append("\n\tsessionTemplate not instantiated or is empty... check previous exceptions");
    }
    sBuilder.append("\nConfiguration Loaded Work Item Handlers :");
    SessionConfiguration ksConfig = (SessionConfiguration) KnowledgeBaseFactory
            .newKnowledgeSessionConfiguration(ksconfigProperties);
    try {
        Map<String, WorkItemHandler> wiHandlers = ksConfig.getWorkItemHandlers();
        if (wiHandlers.size() == 0) {
            sBuilder.append("\n\t no work item handlers defined");
            Properties badProps = createPropsFromDroolsSessionConf();
            if (badProps == null)
                sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH);
            else
                sBuilder.append("\n\tlocated" + DROOLS_SESSION_CONF_PATH);
        } else {
            for (String name : wiHandlers.keySet()) {
                sBuilder.append("\n\t");
                sBuilder.append(name);
                sBuilder.append(" : ");
                Class wiClass = wiHandlers.get(name).getClass();
                sBuilder.append(wiClass);
            }
        }
    } catch (NullPointerException x) {
        sBuilder.append(
                "\n\tError intializing at least one of the configured work item handlers via drools.session.conf.\n\tEnsure all space delimited work item handlers listed in drools.session.conf exist on the classpath");
        Properties badProps = createPropsFromDroolsSessionConf();
        if (badProps == null) {
            sBuilder.append("\n\tunable to locate " + DROOLS_SESSION_CONF_PATH);
        } else {
            try {
                Enumeration badEnums = badProps.propertyNames();
                while (badEnums.hasMoreElements()) {
                    String handlerConfName = (String) badEnums.nextElement();
                    if (DROOLS_WORK_ITEM_HANDLERS.equals(handlerConfName)) {
                        String[] badHandlerNames = ((String) badProps.get(handlerConfName)).split("\\s");
                        for (String badHandlerName : badHandlerNames) {
                            sBuilder.append("\n\t\t");
                            sBuilder.append(badHandlerName);
                            InputStream iStream = this.getClass()
                                    .getResourceAsStream("/META-INF/" + badHandlerName);
                            if (iStream != null) {
                                sBuilder.append("\t : found on classpath");
                                iStream.close();
                            } else {
                                sBuilder.append("\t : NOT FOUND on classpath !!!!!  ");
                            }
                        }
                    }
                }
            } catch (Exception y) {
                y.printStackTrace();
            }
        }
    } catch (org.mvel2.CompileException x) {
        sBuilder.append("\n\t located " + DROOLS_SESSION_CONF_PATH);
        sBuilder.append(
                "\n\t however, following ClassNotFoundException encountered when instantiating defined work item handlers : \n\t\t");
        sBuilder.append(x.getLocalizedMessage());
    }
    sBuilder.append("\n");
    return sBuilder.toString();
}