Example usage for java.lang NullPointerException getMessage

List of usage examples for java.lang NullPointerException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.auraframework.util.AuraUITestingUtil.java

/**
 * Evaluate the given javascript in the current window. Upon completion, if the framework has loaded and is in a
 * test mode, then assert that there are no uncaught javascript errors.
 * <p>/* w ww . j a  va2 s . c  o  m*/
 * As an implementation detail, we accomplish this by wrapping the given javascript so that we can perform the error
 * check on each evaluation without doing a round-trip to the browser (which might be long in cases of remote test
 * runs).
 * 
 * @return the result of calling {@link JavascriptExecutor#executeScript(String, Object...) with the given
 *         javascript and args.
 */
public Object getEval(final String javascript, Object... args) {
    /**
     * Wrapping the javascript on the native Android browser is broken. By not using the wrapper we won't catch any
     * javascript errors here, but on passing cases this should behave the same functionally. See W-1481593.
     */
    if (driver instanceof RemoteWebDriver
            && "android".equals(((RemoteWebDriver) driver).getCapabilities().getBrowserName())) {
        return getRawEval(javascript, args);
    }

    /**
     * Wrap the given javascript to evaluate and then check for any collected errors. Then, return the result and
     * errors back to the WebDriver. We must return as an array because
     * {@link JavascriptExecutor#executeScript(String, Object...)} cannot handle Objects as return values."
     */
    String escapedJavascript = StringEscapeUtils.escapeEcmaScript(javascript);
    String wrapper = "var ret,scriptExecException;"
            + String.format("var func = new Function('arguments', \"%s\");\n", escapedJavascript) + "try\n{"
            + " ret = func.call(this, arguments);\n" + "}\n" + "catch(e){\n"
            + " scriptExecException = e.message || e.toString();\n" + "}\n" + //
            "var jstesterrors = (window.$A && window.$A.test) ? window.$A.test.getErrors() : '';\n"
            + "return [ret, jstesterrors, scriptExecException];";

    try {
        @SuppressWarnings("unchecked")
        List<Object> wrapResult = (List<Object>) getRawEval(wrapper, args);
        Assert.assertEquals("Wrapped javsascript execution expects an array of exactly 3 elements", 3,
                wrapResult.size());
        Object exception = wrapResult.get(2);
        Assert.assertNull(
                "Following JS Exception occured while evaluating provided script:\n" + exception + "\n"
                        + "Arguments: (" + Arrays.toString(args) + ")\n" + "Script:\n" + javascript + "\n",
                exception);
        String errors = (String) wrapResult.get(1);
        assertJsTestErrors(errors);
        rerunCount = 0;
        return wrapResult.get(0);
    } catch (WebDriverException e) {
        // shouldn't come here that often as we are also wrapping the js
        // script being passed to us in try/catch above
        Assert.fail("Script execution failed.\n" + "Exception type: " + e.getClass().getName() + "\n"
                + "Failure Message: " + e.getMessage() + "\n" + "Arguments: (" + Arrays.toString(args) + ")\n"
                + "Script:\n" + javascript + "\n");
        throw e;
    } catch (NullPointerException npe) {
        // Although it should never happen, ios-driver is occasionally returning null when trying to execute the
        // wrapped javascript. Re-run the script a couple more times before failing.
        if (++rerunCount > 2) {
            Assert.fail("Script execution failed.\n" + "Failure Message: " + npe.getMessage() + "\n"
                    + "Arguments: (" + Arrays.toString(args) + ")\n" + "Script:\n" + javascript + "\n");
        }
        return getEval(javascript, args);
    }
}

From source file:com.sfs.whichdoctor.webservice.RotationServiceImpl.java

/**
 * Load rotations.// w ww .j  av a  2 s  . c  om
 *
 * @param identifier the identifier
 * @param periodFrom the period from
 * @param periodTo the period to
 * @return an XML string of rotation data
 */
private PersonsRotations loadRotations(final int identifier, final Calendar periodFrom,
        final Calendar periodTo) {

    SearchBean search = searchDAO.initiate("rotation", new UserBean());
    RotationBean criteria = (RotationBean) search.getSearchCriteria();
    RotationBean constraints = (RotationBean) search.getSearchConstraints();

    // Load the person based on the supplied identifier to get their division
    String division = "";
    int personGUID = 0;

    try {
        BuilderBean loadDetails = new BuilderBean();
        loadDetails.setParameter("MEMBERSHIP", true);

        PersonBean loadPerson = personDAO.loadIdentifier(identifier, loadDetails);

        personGUID = loadPerson.getGUID();

        if (StringUtils.isNotBlank(loadPerson.getMembershipField("Division"))) {
            division = loadPerson.getMembershipField("Division").substring(0, 1).toUpperCase();
        }
    } catch (WhichDoctorDaoException wde) {
        logger.error("Error loading person (" + identifier + "): " + wde.getMessage());
    } catch (NullPointerException npe) {
        logger.error("Error person found (" + identifier + "): " + npe.getMessage());
    }

    PersonBean person = new PersonBean();
    person.setPersonIdentifier(identifier);

    criteria.setPersonSearch(person);

    Date dateTo = DataFilter.parseDate("31/12/2037", false);
    Date dateFrom = DataFilter.parseDate("1/1/1900", false);

    if (periodTo != null) {
        dateTo = new Date(periodTo.getTime().getTime());
    }
    if (periodFrom != null) {
        dateFrom = new Date(periodFrom.getTime().getTime());
    }

    criteria.setStartDate(dateTo);
    constraints.setStartDate(DataFilter.parseDate("1/1/1900", false));

    criteria.setEndDate(dateFrom);
    constraints.setEndDate(DataFilter.parseDate("31/12/2037", false));

    search.setSearchCriteria(criteria);
    search.setSearchConstraints(constraints);
    search.setLimit(0);

    BuilderBean loadDetails = new BuilderBean();
    loadDetails.setParameter("ACCREDITATIONS", true);
    loadDetails.setParameter("ASSESSMENTS", true);
    loadDetails.setParameter("SUPERVISORS", true);

    // Load the list of relevant rotations
    SearchResultsBean results = null;
    try {
        results = searchDAO.search(search, loadDetails);
    } catch (WhichDoctorSearchDaoException wse) {
        logger.error("Error performing search for rotations: " + wse.getMessage());
    }

    List<RotationBean> rotations = new ArrayList<RotationBean>();
    if (results != null && results.getSearchResults() != null) {
        for (Object obj : results.getSearchResults()) {
            RotationBean rotation = (RotationBean) obj;
            rotations.add(rotation);
        }
    }

    List<RotationBean> currentRotations = new ArrayList<RotationBean>();
    try {
        Collection<RotationBean> crtns = this.rotationDAO.loadCurrentForPerson(personGUID);
        if (crtns != null) {
            for (RotationBean rtn : crtns) {
                if (rtn != null) {
                    currentRotations.add(rtn);
                }
            }
        }

    } catch (WhichDoctorDaoException wde) {
        logger.error("Error loading current rotations: " + wde.getMessage());
    }

    return new PersonsRotations(division, rotations, currentRotations);
}

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;
        }/*  w w  w  . ja  v  a2s. c  o m*/
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

/**
 * Zeigt eine Warnung an Project: SubmatixBTConfigPC Package: de.dmarcini.submatix.pclogger.gui
 * /*  ww  w.  j a v a 2  s.c  om*/
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 07.01.2012
 * @param msg
 *          Warnmessage
 */
private void showWarnBox(String msg) {
    ImageIcon icon = null;
    try {
        icon = new ImageIcon(MainCommGUI.class.getResource("/de/dmarcini/submatix/pclogger/res/Abort.png"));
        JOptionPane.showMessageDialog(this, msg, LangStrings.getString("MainCommGUI.warnDialog.headline"),
                JOptionPane.WARNING_MESSAGE, icon);
    } catch (NullPointerException ex) {
        lg.error("ERROR showWarnDialog <" + ex.getMessage() + "> ABORT!");
        return;
    } catch (MissingResourceException ex) {
        lg.error("ERROR showWarnDialog <" + ex.getMessage() + "> ABORT!");
        return;
    } catch (ClassCastException ex) {
        lg.error("ERROR showWarnDialog <" + ex.getMessage() + "> ABORT!");
        return;
    }
}

From source file:org.phaidra.apihooks.APISOAPHooksImpl.java

/**
 * Runs the hook if enabled in fedora.fcfg.
 *
 * @param method The name of the method that calls the hook
 * @param pid The PID that is being accessed
 * @param params Method parameters, depend on the method called
 * @return String Hook verdict. Begins with "OK" if it's ok to proceed.
 * @throws APIHooksException If the remote call went wrong
 *///from  ww  w  .ja v  a2s .co  m
public String runHook(String method, DOWriter w, Context context, String pid, Object[] params)
        throws APIHooksException {
    String rval = null;

    // Only do this if the method is enabled in fedora.fcfg
    if (getParameter(method) == null) {
        log.debug("runHook: method |" + method + "| not configured, not calling webservice");
        return "OK";
    }

    Iterator i = context.subjectAttributes();
    Set<String> attrs = new HashSet<String>();
    while (i.hasNext()) {
        String name = "";
        try {
            name = (String) i.next();
            String[] value = context.getSubjectValues(name);
            for (int j = 0; j < value.length; j++) {
                attrs.add(name + "=" + value[j]);
            }
        } catch (NullPointerException ex) {
            log.debug(
                    "runHook: caught NullPointerException while trying to retrieve subject attribute " + name);
        }
    }
    for (Iterator<String> j = attrs.iterator(); j.hasNext();) {
        log.debug("runHook: will send |" + j.next() + "| as subject attribute");
    }

    String loginId = context.getSubjectValue(Constants.SUBJECT.LOGIN_ID.uri);

    log.debug("runHook: called for method=|" + method + "|, pid=|" + pid + "|");
    try {
        Service service = new Service();
        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(new java.net.URL(getParameter("soapproxy")));
        call.setOperationName(new QName(getParameter("soapuri"), getParameter("soapmethod")));
        // TODO: timeout? retries?
        rval = (String) call.invoke(new Object[] { method, loginId, pid, params, attrs.toArray() });

        log.debug("runHook: successful SOAP invocation for method |" + method + "|, returning " + rval);
    } catch (Exception ex) {
        log.error("runHook: error calling SOAP hook: " + ex.getMessage());
        throw new APIHooksException("Error calling SOAP hook: " + ex.getMessage(), ex);
    }

    return processResults(rval, w, context);
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

/**
 * Setze alle Strings in die entsprechende Landessprache! Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from  w  ww .  j  a v  a 2 s .  co  m
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 22.04.2012
 * @return in Ordnung oder nicht
 */
public int setLanguageStrings() {
    try {
        deviceComboBox.setToolTipText(LangStrings.getString("spx42LogGraphPanel.deviceComboBox.tooltiptext"));
        diveSelectComboBox
                .setToolTipText(LangStrings.getString("spx42LogGraphPanel.diveSelectComboBox.tooltiptext"));
        computeGraphButton.setText(LangStrings.getString("spx42LogGraphPanel.computeGraphButton.text"));
        computeGraphButton
                .setToolTipText(LangStrings.getString("spx42LogGraphPanel.computeGraphButton.tooltiptext"));
        detailGraphButton.setText(LangStrings.getString("spx42LogGraphPanel.detailGraphButton.text"));
        detailGraphButton
                .setToolTipText(LangStrings.getString("spx42LogGraphPanel.detailGraphButton.tooltiptext"));
        maxDepthLabelString = LangStrings.getString("spx42LogGraphPanel.maxDepthLabel.text");
        coldestLabelString = LangStrings.getString("spx42LogGraphPanel.coldestLabel.text");
        diveLenLabelString = LangStrings.getString("spx42LogGraphPanel.diveLenLabel.text");
        notesEditButton
                .setToolTipText(LangStrings.getString("spx42LogGraphPanel.computeGraphButton.tooltiptext"));
    } catch (NullPointerException ex) {
        System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
        return (-1);
    } catch (MissingResourceException ex) {
        System.out.println(
                "ERROR set language strings - the given key can be found <" + ex.getMessage() + "> ABORT!");
        return (0);
    } catch (ClassCastException ex) {
        System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
        return (0);
    }
    clearDiveComboBox();
    return (1);
}

From source file:AppSpringLayout.java

/**
 * Initialize the contents of the frame.
 *///from  w ww.  ja  v  a  2  s .com
private void initialize() {

    frame = new JFrame();
    frame.setBounds(0, 0, 850, 750);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    springLayout = new SpringLayout();
    frame.getContentPane().setLayout(springLayout);
    frame.setLocationRelativeTo(null);

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png");
    fc = new JFileChooser();
    fc.setFileFilter(filter);
    // frame.getContentPane().add(fc);

    btnTurnCameraOn = new JButton("Turn camera on");
    springLayout.putConstraint(SpringLayout.WEST, btnTurnCameraOn, 51, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, btnTurnCameraOn, -581, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(btnTurnCameraOn);

    urlTextField = new JTextField();
    springLayout.putConstraint(SpringLayout.SOUTH, btnTurnCameraOn, -6, SpringLayout.NORTH, urlTextField);
    springLayout.putConstraint(SpringLayout.WEST, urlTextField, 0, SpringLayout.WEST, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.EAST, urlTextField, 274, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(urlTextField);
    urlTextField.setColumns(10);

    originalImageLabel = new JLabel("");
    springLayout.putConstraint(SpringLayout.NORTH, originalImageLabel, 102, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, originalImageLabel, 34, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, originalImageLabel, -326, SpringLayout.SOUTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, originalImageLabel, -566, SpringLayout.EAST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, urlTextField, -6, SpringLayout.NORTH, originalImageLabel);
    frame.getContentPane().add(originalImageLabel);

    btnAnalyseImage = new JButton("Analyse image");
    springLayout.putConstraint(SpringLayout.NORTH, btnAnalyseImage, 6, SpringLayout.SOUTH, originalImageLabel);
    springLayout.putConstraint(SpringLayout.WEST, btnAnalyseImage, 58, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, btnAnalyseImage, 252, SpringLayout.WEST,
            frame.getContentPane());
    frame.getContentPane().add(btnAnalyseImage);

    lblTags = new JLabel("Tags:");
    frame.getContentPane().add(lblTags);

    lblDescription = new JLabel("Description:");
    springLayout.putConstraint(SpringLayout.WEST, lblDescription, 84, SpringLayout.EAST, lblTags);
    springLayout.putConstraint(SpringLayout.NORTH, lblTags, 0, SpringLayout.NORTH, lblDescription);
    springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 6, SpringLayout.SOUTH, btnAnalyseImage);
    springLayout.putConstraint(SpringLayout.SOUTH, lblDescription, -269, SpringLayout.SOUTH,
            frame.getContentPane());
    frame.getContentPane().add(lblDescription);

    tagsTextArea = new JTextArea();
    springLayout.putConstraint(SpringLayout.NORTH, tagsTextArea, 459, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, tagsTextArea, 10, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, tagsTextArea, -727, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(tagsTextArea);

    descriptionTextArea = new JTextArea();
    springLayout.putConstraint(SpringLayout.NORTH, descriptionTextArea, 0, SpringLayout.SOUTH, lblDescription);
    springLayout.putConstraint(SpringLayout.WEST, descriptionTextArea, 18, SpringLayout.EAST, tagsTextArea);
    descriptionTextArea.setLineWrap(true);
    descriptionTextArea.setWrapStyleWord(true);
    frame.getContentPane().add(descriptionTextArea);

    lblImageType = new JLabel("Image type");
    springLayout.putConstraint(SpringLayout.WEST, lblTags, 0, SpringLayout.WEST, lblImageType);
    springLayout.putConstraint(SpringLayout.NORTH, lblImageType, 10, SpringLayout.SOUTH, tagsTextArea);
    springLayout.putConstraint(SpringLayout.WEST, lblImageType, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblImageType);

    lblSize = new JLabel("Size");
    springLayout.putConstraint(SpringLayout.NORTH, lblSize, 21, SpringLayout.SOUTH, lblImageType);
    springLayout.putConstraint(SpringLayout.WEST, lblSize, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblSize);

    lblLicense = new JLabel("License");
    springLayout.putConstraint(SpringLayout.WEST, lblLicense, 20, SpringLayout.WEST, frame.getContentPane());
    frame.getContentPane().add(lblLicense);

    lblSafeSearch = new JLabel("Safe search");
    springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch, 10, SpringLayout.WEST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch, 139, SpringLayout.SOUTH,
            frame.getContentPane());
    frame.getContentPane().add(lblSafeSearch);

    String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" };
    licenseBox = new JComboBox(licenseTypes);
    springLayout.putConstraint(SpringLayout.WEST, licenseBox, 28, SpringLayout.EAST, lblLicense);
    frame.getContentPane().add(licenseBox);

    String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" };
    sizeBox = new JComboBox(sizeTypes);
    springLayout.putConstraint(SpringLayout.WEST, sizeBox, 50, SpringLayout.EAST, lblSize);
    springLayout.putConstraint(SpringLayout.EAST, sizeBox, -556, SpringLayout.EAST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, licenseBox, 0, SpringLayout.EAST, sizeBox);
    frame.getContentPane().add(sizeBox);

    String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" };
    imageTypeBox = new JComboBox(imageTypes);
    springLayout.putConstraint(SpringLayout.SOUTH, descriptionTextArea, -6, SpringLayout.NORTH, imageTypeBox);
    springLayout.putConstraint(SpringLayout.NORTH, imageTypeBox, 547, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, tagsTextArea, -6, SpringLayout.NORTH, imageTypeBox);
    springLayout.putConstraint(SpringLayout.WEST, imageTypeBox, 6, SpringLayout.EAST, lblImageType);
    springLayout.putConstraint(SpringLayout.EAST, imageTypeBox, -556, SpringLayout.EAST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, sizeBox, 10, SpringLayout.SOUTH, imageTypeBox);
    frame.getContentPane().add(imageTypeBox);

    btnBrowse = new JButton("Browse");
    springLayout.putConstraint(SpringLayout.WEST, btnBrowse, 0, SpringLayout.WEST, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.EAST, btnBrowse, -583, SpringLayout.EAST, frame.getContentPane());
    frame.getContentPane().add(btnBrowse);

    lblSafeSearch_1 = new JLabel("Safe search");
    springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch_1, 20, SpringLayout.WEST,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, lblLicense, -17, SpringLayout.NORTH, lblSafeSearch_1);
    frame.getContentPane().add(lblSafeSearch_1);

    String[] safeSearchTypes = { "Strict", "Moderate", "Off" };
    safeSearchBox = new JComboBox(safeSearchTypes);
    springLayout.putConstraint(SpringLayout.SOUTH, licenseBox, -6, SpringLayout.NORTH, safeSearchBox);
    springLayout.putConstraint(SpringLayout.WEST, safeSearchBox, 4, SpringLayout.EAST, lblSafeSearch_1);
    springLayout.putConstraint(SpringLayout.EAST, safeSearchBox, 0, SpringLayout.EAST, licenseBox);
    frame.getContentPane().add(safeSearchBox);

    btnSearchForSimilar = new JButton("Search for similar images");
    springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch_1, -13, SpringLayout.NORTH,
            btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.SOUTH, safeSearchBox, -6, SpringLayout.NORTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.NORTH, btnSearchForSimilar, 689, SpringLayout.NORTH,
            frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, btnSearchForSimilar, 36, SpringLayout.WEST,
            frame.getContentPane());
    frame.getContentPane().add(btnSearchForSimilar);

    btnCancel = new JButton("Cancel");
    springLayout.putConstraint(SpringLayout.NORTH, btnCancel, 0, SpringLayout.NORTH, btnBrowse);
    btnCancel.setVisible(false);
    frame.getContentPane().add(btnCancel);

    btnSave = new JButton("Save");
    springLayout.putConstraint(SpringLayout.WEST, btnCancel, 6, SpringLayout.EAST, btnSave);
    springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH, btnBrowse);
    btnSave.setVisible(false);
    frame.getContentPane().add(btnSave);

    btnTakeAPicture = new JButton("Take a picture");
    springLayout.putConstraint(SpringLayout.WEST, btnTakeAPicture, 114, SpringLayout.EAST, btnBrowse);
    springLayout.putConstraint(SpringLayout.WEST, btnSave, 6, SpringLayout.EAST, btnTakeAPicture);
    springLayout.putConstraint(SpringLayout.NORTH, btnTakeAPicture, 0, SpringLayout.NORTH, btnBrowse);
    btnTakeAPicture.setVisible(false);
    frame.getContentPane().add(btnTakeAPicture);

    //// JScrollPane scroll = new JScrollPane(list);
    // Constraints c = springLayout.getConstraints(list);
    // frame.getContentPane().add(scroll, c);

    list = new JList();
    JScrollPane scroll = new JScrollPane(list);
    springLayout.putConstraint(SpringLayout.EAST, descriptionTextArea, -89, SpringLayout.WEST, list);
    springLayout.putConstraint(SpringLayout.EAST, list, -128, SpringLayout.EAST, frame.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, list, 64, SpringLayout.EAST, licenseBox);
    springLayout.putConstraint(SpringLayout.NORTH, list, 0, SpringLayout.NORTH, btnTurnCameraOn);
    springLayout.putConstraint(SpringLayout.SOUTH, list, -35, SpringLayout.SOUTH, lblSafeSearch_1);

    Constraints c = springLayout.getConstraints(list);
    frame.getContentPane().add(scroll, c);

    // frame.getContentPane().add(list);

    progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 15, SpringLayout.SOUTH, list);
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 24, SpringLayout.EAST, safeSearchBox);
    springLayout.putConstraint(SpringLayout.EAST, progressBar, 389, SpringLayout.WEST, btnTakeAPicture);
    progressBar.setIndeterminate(true);
    progressBar.setStringPainted(true);
    progressBar.setVisible(false);
    Border border = BorderFactory
            .createTitledBorder("We are checking every image, pixel by pixel, it may take a while...");
    progressBar.setBorder(border);
    frame.getContentPane().add(progressBar);

    labelTryLinks = new JLabel();
    labelTryLinks.setVisible(false);
    springLayout.putConstraint(SpringLayout.NORTH, labelTryLinks, -16, SpringLayout.SOUTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.WEST, labelTryLinks, -61, SpringLayout.EAST, licenseBox);
    springLayout.putConstraint(SpringLayout.SOUTH, labelTryLinks, 0, SpringLayout.SOUTH, btnSearchForSimilar);
    springLayout.putConstraint(SpringLayout.EAST, labelTryLinks, 0, SpringLayout.EAST, licenseBox);
    frame.getContentPane().add(labelTryLinks);

    lblFoundLinks = new JLabel("");
    springLayout.putConstraint(SpringLayout.NORTH, lblFoundLinks, -29, SpringLayout.NORTH, progressBar);
    springLayout.putConstraint(SpringLayout.WEST, lblFoundLinks, 6, SpringLayout.EAST, scroll);
    springLayout.putConstraint(SpringLayout.SOUTH, lblFoundLinks, -13, SpringLayout.NORTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, lblFoundLinks, -10, SpringLayout.EAST,
            frame.getContentPane());
    frame.getContentPane().add(lblFoundLinks);

    numberOfImagesToSearchFor = new JTextField();
    springLayout.putConstraint(SpringLayout.NORTH, numberOfImagesToSearchFor, 0, SpringLayout.NORTH,
            tagsTextArea);
    springLayout.putConstraint(SpringLayout.WEST, numberOfImagesToSearchFor, 6, SpringLayout.EAST,
            descriptionTextArea);
    springLayout.putConstraint(SpringLayout.EAST, numberOfImagesToSearchFor, -36, SpringLayout.WEST, scroll);
    frame.getContentPane().add(numberOfImagesToSearchFor);
    numberOfImagesToSearchFor.setColumns(10);

    JLabel lblNumberOfImages = new JLabel("Number");
    springLayout.putConstraint(SpringLayout.NORTH, lblNumberOfImages, 0, SpringLayout.NORTH, lblTags);
    springLayout.putConstraint(SpringLayout.WEST, lblNumberOfImages, 31, SpringLayout.EAST, btnAnalyseImage);
    springLayout.putConstraint(SpringLayout.EAST, lblNumberOfImages, -6, SpringLayout.WEST, scroll);
    frame.getContentPane().add(lblNumberOfImages);

    // label to get coordinates for web camera panel
    // lblNewLabel_1 = new JLabel("New label");
    // springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 0,
    // SpringLayout.NORTH, btnTurnCameraOn);
    // springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 98,
    // SpringLayout.EAST, originalImagesLabel);
    // springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -430,
    // SpringLayout.SOUTH, lblSafeSearch_1);
    // springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, 0,
    // SpringLayout.EAST, btnCancel);
    // frame.getContentPane().add(lblNewLabel_1);

    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                openFilechooser();
            }
        }
    });

    btnTurnCameraOn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("turn camera on");
            turnCameraOn();
            btnCancel.setVisible(true);
            btnTakeAPicture.setVisible(true);
        }
    });

    btnTakeAPicture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            btnSave.setVisible(true);
            imageWebcam = webcam.getImage();
            originalImage = imageWebcam;

            // to mirror the image we create a temporary file, flip it
            // horizontally and then delete

            // get user's name to store file in the user directory
            String user = System.getProperty("user.home");
            String fileName = user + "/webCamPhoto.jpg";
            File newFile = new File(fileName);

            try {
                ImageIO.write(originalImage, "jpg", newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                originalImage = (BufferedImage) ImageIO.read(newFile);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            newFile.delete();
            originalImage = mirrorImage(originalImage);
            icon = scaleBufferedImage(originalImage, originalImageLabel);
            originalImageLabel.setIcon(icon);
        }
    });

    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {

                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if image already exists
                    if (output.exists()) {
                        int response = JOptionPane.showConfirmDialog(null, //
                                "Do you want to replace the existing file?", //
                                "Confirm", JOptionPane.YES_NO_OPTION, //
                                JOptionPane.QUESTION_MESSAGE);
                        if (response != JOptionPane.YES_OPTION) {
                            return;
                        }
                    }
                    ImageIO.write(toBufferedImage(originalImage), "jpg", output);
                    System.out.println("Your image has been saved in the folder " + file.getPath());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            btnTakeAPicture.setVisible(false);
            btnCancel.setVisible(false);
            btnSave.setVisible(false);
            webcam.close();
            panel.setVisible(false);
        }
    });

    urlTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (urlTextField.getText().length() > 0) {
                String linkNew = urlTextField.getText();
                displayImage(linkNew, originalImageLabel);
                originalImage = imageResponses;
            }
        }
    });

    btnAnalyseImage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Token computerVisionToken = new Token();
            String computerVisionTokenFileName = "APIToken.txt";

            try {
                computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName);
                try {
                    analyse();
                } catch (NullPointerException e1) {
                    // if user clicks on "analyze" button without uploading
                    // image or posts a broken link
                    JOptionPane.showMessageDialog(null, "Please choose an image");
                    e1.printStackTrace();
                }
            } catch (NullPointerException e1) {
                e1.printStackTrace();
            }
        }
    });

    btnSearchForSimilar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            listModel.clear();

            Token bingImageToken = new Token();
            String bingImageTokenFileName = "SearchApiToken.txt";
            bingToken = bingImageToken.getApiToken(bingImageTokenFileName);

            // in case user edited description or tags, update it and
            // replace new line character, spaces and breaks with %20
            text = descriptionTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20");
            String tagsString = tagsTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n",
                    "%20");

            String numberOfImages = numberOfImagesToSearchFor.getText();

            try {
                int numberOfImagesTry = Integer.parseInt(numberOfImages);
                System.out.println(numberOfImagesTry);

                imageTypeString = imageTypeBox.getSelectedItem().toString();
                sizeTypeString = sizeBox.getSelectedItem().toString();
                licenseTypeString = licenseBox.getSelectedItem().toString();
                safeSearchTypeString = safeSearchBox.getSelectedItem().toString();

                searchParameters = tagsString + text;
                System.out.println("search parameters: " + searchParameters);

                if (searchParameters.length() != 0) {

                    // add new thread for searching, so that progress bar
                    // and searching could run simultaneously
                    Thread t1 = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisible(true);
                            workingUrls = searchToDisplayOnJList(searchParameters, imageTypeString,
                                    sizeTypeString, licenseTypeString, safeSearchTypeString, numberOfImages);
                        }
                    });
                    // start searching in a separate thread
                    t1.start();
                } else {
                    JOptionPane.showMessageDialog(null,
                            "Please choose first an image to analyse or insert search parameters");
                }
            } catch (NumberFormatException e1) {
                JOptionPane.showMessageDialog(null, "Please insert a valid number of images to search for");
                e1.printStackTrace();

            }
        }
    });

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            int i = list.getSelectedIndex();

            if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
                try {
                    file = fc.getSelectedFile();
                    File output = new File(file.toString());
                    // check if file already exists, ask user if they
                    // wish to overwrite it
                    if (output.exists()) {
                        int response = JOptionPane.showConfirmDialog(null, //
                                "Do you want to replace the existing file?", //
                                "Confirm", JOptionPane.YES_NO_OPTION, //
                                JOptionPane.QUESTION_MESSAGE);
                        if (response != JOptionPane.YES_OPTION) {
                            return;
                        }
                    }
                    try {

                        URL fileNameAsUrl = new URL(linksResponse[i]);
                        originalImage = ImageIO.read(fileNameAsUrl);
                        ImageIO.write(toBufferedImage(originalImage), "jpeg", output);
                        System.out.println("image saved, in the folder: " + output.getAbsolutePath());

                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } catch (NullPointerException e2) {
                    e2.getMessage();
                }
            }
        }
    });
}

From source file:org.apache.zeppelin.spark.OldSparkInterpreter.java

private void putLatestVarInResourcePool(InterpreterContext context) {
    String varName = (String) Utils.invokeMethod(intp, "mostRecentVar");
    if (varName == null || varName.isEmpty()) {
        return;//from   ww  w.j a  v  a 2 s. c o m
    }
    Object lastObj = null;
    try {
        if (Utils.isScala2_10()) {
            lastObj = getValue(varName);
        } else {
            lastObj = getLastObject();
        }
    } catch (NullPointerException e) {
        // Some case, scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call throws an NPE
        logger.error(e.getMessage(), e);
    }

    if (lastObj != null) {
        ResourcePool resourcePool = context.getResourcePool();
        resourcePool.put(context.getNoteId(), context.getParagraphId(),
                WellKnownResourceName.ZeppelinReplResult.toString(), lastObj);
    }
}

From source file:it.cg.main.process.mapping.easyway.MapperProductAssetToPASS.java

/**
 * Metodo custom di quoteDtoToAsset//from w w w  .  ja  v a 2 s .c o m
 * @param inb
 * @return
 */
public List<WsVehicle> quoteToWsVehicle(InboundRequestHttpJSON inb) {
    logger.debug("quoteToWsVehicle set frome vehicle with input : " + inb);
    ArrayList<WsVehicle> ve = new ArrayList<WsVehicle>();
    WsVehicle wsVe = new WsVehicle();

    String ccode = getRiskTypeAsset(inb, inb.getInboundQuoteDTO().getOtherVehicle());
    logger.debug("quoteToWsVehicle ClassCode = " + ccode);
    wsVe.setClassCode(ccode);
    logger.debug("quoteToWsVehicle SectorCode = " + this.sectorCode);
    wsVe.setSectorCode(this.sectorCode);

    String useCode = "";
    try {
        if (inb.getInboundQuoteDTO().getVehicle().getTechnicalData().getPraUse()
                .equals(EnumPublicRegisterUse.MIXED)) {
            useCode = "000007";
        } else if (inb.getInboundQuoteDTO().getVehicle().getTechnicalData().getPraUse()
                .equals(EnumPublicRegisterUse.PRIVATE_CAR)) {
            useCode = "000005";
        }
    } catch (NullPointerException ex) {
        logger.error("Into quoteToWsVehicle something null into quote, impossible set useCode for Vehicle : "
                + ex.getMessage());
    }

    logger.debug("quoteToWsVehicle UseCode = " + useCode);
    wsVe.setUseCode(useCode);

    ve.add(wsVe);

    logger.debug("quoteToWsVehicle set from vehicle with output : " + ve);
    return ve;
}

From source file:org.totschnig.myexpenses.fragment.CategoryList.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    int id = loader.getId();
    if (id == SORTABLE_CURSOR) {
        mGroupCursor = null;/*from w  ww.  jav  a  2s .  co  m*/
        mAdapter.setGroupCursor(null);
    } else if (id > 0) {
        // child cursor
        try {
            mAdapter.setChildrenCursor(id, null);
        } catch (NullPointerException e) {
            Log.w("TAG", "Adapter expired, try again on the next query: " + e.getMessage());
        }
    }
}