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:MainClass.java

public static void main(String[] args) {
    String input = null;//from ww w  . j a v a 2 s  . co  m
    try {
        String capitalized = capitalize(input);
        System.out.println(capitalized);
    } catch (NullPointerException e) {
        System.out.println(e.toString());
    }
}

From source file:Main.java

public static void sendBroadcast(String filter, Context context) {
    Intent startupIntent = new Intent(filter);

    try {//from w  w  w  . j  av  a2 s  . c  o m
        context.sendBroadcast(startupIntent);
    } catch (NullPointerException ex) {
        Log.e(TAG, "Intent broadcast failed. Error: " + ex.toString());
    }
}

From source file:Main.java

public static Bitmap createDrawableFromView(Context context, View view) {

    Bitmap bit = null;/*from   www  . ja  v a2  s. c  om*/
    try {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT));
        view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
        view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
        view.buildDrawingCache();
        bit = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bit);
        view.draw(canvas);
    } catch (NullPointerException e) {
        Log.e("NullPointerException", e.toString());
        e.printStackTrace();
    }
    return bit;
}

From source file:org.openmrs.mobile.models.mappers.ObservationMapper.java

public static Encounter lastVitalsMap(JSONObject jsonObject) {
    Encounter encounter = null;/* w  ww.  j  av  a 2  s  . c o m*/
    try {
        encounter = parseLastVitalsAfterFormSending(jsonObject);
    } catch (JSONException e) {
        OpenMRS.getInstance().getOpenMRSLogger()
                .d("Failed to parse LastVitals encounter. Trying to parse different JSON model.");
        try {
            encounter = parseOtherLastVitalsEncounterResponse(jsonObject);
        } catch (JSONException je) {
            OpenMRS.getInstance().getOpenMRSLogger().d(je.toString());
            OpenMRS.getInstance().getOpenMRSLogger()
                    .d("Failed to parse LastVitals encounter different JSON model.");
        } catch (NullPointerException ne) {
            OpenMRS.getInstance().getOpenMRSLogger().d(ne.toString());
            OpenMRS.getInstance().getOpenMRSLogger()
                    .d("Failed to parse LastVitals encounter! Response returned empty encounter type!");
            return null;
        }
    }
    return encounter;
}

From source file:com.stacksync.desktop.Stacksync.java

public static void start() {
    Boolean deamonMode = false;//from  w ww . ja va2  s . c om
    Boolean extendedMode;

    try {
        try {
            File file = new File(env.getDefaultUserConfigDir() + File.separator + "conf" + File.separator
                    + Constants.LOGGING_DEFAULT_FILENAME);
            DOMConfigurator.configure(file.toURI().toURL());
        } catch (NullPointerException e) {
            System.out.println(
                    "No log4j config file was found no logs will be saved for this stacksync instance please make sure LogProperties.xml file is correctly placed "
                            + e.toString());
        } catch (MalformedURLException ex) {
            System.out.println(
                    "No log4j config file was found no logs will be saved for this stacksync instance please make sure LogProperties.xml file is correctly placed "
                            + ex.toString());
        }

        // create the command line parser
        Options options = createOptions();
        CommandLine line = parser.parse(options, args);

        // Help
        if (line.hasOption("help")) {
            showHelp(options);
        }

        deamonMode = line.hasOption("daemon");
        config.setDaemonMode(deamonMode);
        extendedMode = line.hasOption("extended");
        config.setExtendedMode(extendedMode);

        // Load config
        if (line.hasOption("config")) {
            File configFolder = new File(line.getOptionValue("config"));
            File configFile = new File(line.getOptionValue("config") + File.separator + "config.xml");

            if (configFolder.exists() && configFile.exists()) {
                config.load(configFolder);
            } else {
                if (!configFolder.exists()) {
                    throw new ConfigException("config folder " + configFolder + " doesn't exist.");
                } else {
                    throw new ConfigException(configFile + " doesn't exist.");
                }
            }

            if (config.getProfile() == null) {
                throw new ConfigException("Could not load a profile, check the configuration file.");
            }
        } else {

            File configurationDir = env.getAppConfDir();
            if (configurationDir.exists()) {
                config.load();
                if (config.getProfile() == null) {
                    File folder = new File(
                            config.getConfDir() + File.separator + Constants.CONFIG_DATABASE_DIRNAME);
                    File configFile = new File(
                            config.getConfDir() + File.separator + Constants.CONFIG_FILENAME);

                    folder.delete();
                    configFile.delete();
                    config.load();
                }
            } else { // new configuration
                config.load();
            }
        }

    } catch (ConfigException e) {
        System.err.println("ERROR: Configuration exception: ");
        System.err.println(StringUtil.getStackTrace(e));
        System.exit(1);
    } catch (ParseException e) {
        System.err.println("ERROR: Command line arguments invalid: ");
        System.err.println(StringUtil.getStackTrace(e));
        System.exit(1);
    }

    // Start app!
    try {
        // TODO fixit
        //RemoteLogs.sendFailedLogs();
        Application appStacksync = new Application();
        appStacksync.start();
    } catch (Exception e) {
        if (!deamonMode) {
            ErrorDialog.showDialog(e);
        }
    }
}

From source file:org.apache.ofbiz.passport.event.GitHubEvents.java

/**
 * Redirect to GitHub login page.//from w w  w  . ja  v  a 2s. co  m
 * 
 * @return 
 */
public static String gitHubRedirect(HttpServletRequest request, HttpServletResponse response) {
    GenericValue oauth2GitHub = getOAuth2GitHubConfig(request);
    if (UtilValidate.isEmpty(oauth2GitHub)) {
        return "error";
    }

    String clientId = oauth2GitHub.getString(PassportUtil.COMMON_CLIENT_ID);
    String returnURI = oauth2GitHub.getString(PassportUtil.COMMON_RETURN_RUL);

    // Get user authorization code
    try {
        String state = System.currentTimeMillis() + String.valueOf((new Random(10)).nextLong());
        request.getSession().setAttribute(SESSION_GITHUB_STATE, state);
        String redirectUrl = TokenEndpoint + AuthorizeUri + "?client_id=" + clientId + "&scope=" + DEFAULT_SCOPE
                + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8") + "&state=" + state;
        Debug.logInfo("Request to GitHub: " + redirectUrl, module);
        response.sendRedirect(redirectUrl);
    } catch (NullPointerException e) {
        String errMsg = UtilProperties.getMessage(resource, "RedirectToGitHubOAuth2NullException",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    } catch (IOException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.toString());
        String errMsg = UtilProperties.getMessage(resource, "RedirectToGitHubOAuth2Error", messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    return "success";
}

From source file:org.apache.ofbiz.passport.event.LinkedInEvents.java

/**
 * Redirect to LinkedIn login page./*ww  w . ja  v  a2 s .  com*/
 * 
 * @return 
 */
public static String linkedInRedirect(HttpServletRequest request, HttpServletResponse response) {
    GenericValue oauth2LinkedIn = getOAuth2LinkedInConfig(request);
    if (UtilValidate.isEmpty(oauth2LinkedIn)) {
        return "error";
    }

    String clientId = oauth2LinkedIn.getString(PassportUtil.ApiKeyLabel);
    String returnURI = oauth2LinkedIn.getString(envPrefix + PassportUtil.ReturnUrlLabel);

    // Get user authorization code
    try {
        String state = System.currentTimeMillis() + String.valueOf((new Random(10)).nextLong());
        request.getSession().setAttribute(SESSION_LINKEDIN_STATE, state);
        String redirectUrl = TokenEndpoint + AuthorizeUri + "?client_id=" + clientId + "&response_type=code"
                + "&scope=" + DEFAULT_SCOPE + "&redirect_uri=" + URLEncoder.encode(returnURI, "UTF-8")
                + "&state=" + state;
        response.sendRedirect(redirectUrl);
    } catch (NullPointerException e) {
        String errMsg = UtilProperties.getMessage(resource, "RedirectToLinkedInOAuth2NullException",
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    } catch (IOException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.toString());
        String errMsg = UtilProperties.getMessage(resource, "RedirectToLinkedInOAuth2Error", messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }

    return "success";
}

From source file:com.github.aynu.yukar.baseline.provider.domain.auth.CertificationDomainTest.java

@Test
public final void test() {
    final Certification user1 = new Certification("user#1", DigestUtils.sha256Hex("password#1"));
    LOG.debug("user1 : {}", user1);
    final CertificationDomain testee = new CertificationDomain(user1);
    try {//from w  ww.  ja v  a2  s  .co  m
        testee.changePassword(null);
        fail();
    } catch (final NullPointerException e) {
        LOG.debug(e.toString());
    }
    try {
        testee.changePassword(StringUtils.EMPTY);
        fail();
    } catch (final IllegalArgumentException e) {
        LOG.debug(e.toString());
    }
    try {
        testee.changePassword("password#1");
        fail();
    } catch (final IllegalArgumentException e) {
        LOG.debug(e.toString());
    }
    final Certification user2 = testee.changePassword("password#2");
    assertThat(user2, is(not(user1)));
    LOG.debug("user2 : {}", user1);
}

From source file:geotag.example.sbickt.SbicktAPITest.java

@Test
public void testNewGeoTag() {
    List<NameValuePair> myData = new ArrayList<NameValuePair>();

    myData.add(new BasicNameValuePair("sbickerl[content]", "test post"));
    myData.add(new BasicNameValuePair("sbickerl[visibility]", "private"));
    myData.add(new BasicNameValuePair("geotag[lat]", "2.548"));
    myData.add(new BasicNameValuePair("geotag[lng]", "2.548"));
    myData.add(new BasicNameValuePair("geotag[alt]", "2.548"));

    try {/*w w  w  .  j av  a  2 s  .  c om*/
        SbicktAPI.newGeoTag(myData);
    } catch (NullPointerException e) {
        fail(e.toString());
    } catch (Exception e) {
        fail("SbicktAPITest -> newGeoTag: " + e.toString());
    }
}

From source file:com.poscoict.license.web.controller.ExceptionControllerAdvice.java

@ExceptionHandler(NullPointerException.class)
public ModelAndView handleNullPointerException(NullPointerException ex) {
    logger.error(ex.toString());
    ModelAndView mv = new ModelAndView(DEFAULT_ERROR_VIEW);
    mv.addObject("name", ex.getClass().getSimpleName());
    mv.addObject("message", "?? ?. ?? ? .");
    return mv;/*from  w w  w. j a v  a  2  s.  c  om*/
}