List of usage examples for java.lang NullPointerException printStackTrace
public void printStackTrace()
From source file:MainClass.java
public static void main(String args[]) { try {//from w ww . j av a2 s . c o m throw new NullPointerException("demo"); } catch (NullPointerException e) { System.out.println("recaught: " + e); e.printStackTrace(); } }
From source file:de.prozesskraft.ptest.Fingerprint.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { // try/* w w w . j a v a2 s . c o m*/ // { // if (args.length != 3) // { // System.out.println("Please specify processdefinition file (xml) and an outputfilename"); // } // // } // catch (ArrayIndexOutOfBoundsException e) // { // System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString()); // } /*---------------------------- get options from ini-file ----------------------------*/ File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(Fingerprint.class) + "/" + "../etc/ptest-fingerprint.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option ohelp = new Option("help", "print this message"); Option ov = new Option("v", "prints version and build-date"); /*---------------------------- create argument options ----------------------------*/ Option opath = OptionBuilder.withArgName("PATH").hasArg() .withDescription( "[mandatory; default: .] the root path for the tree you want to make a fingerprint from.") // .isRequired() .create("path"); Option osizetol = OptionBuilder.withArgName("FLOAT").hasArg().withDescription( "[optional; default: 0.02] the sizeTolerance (as factor in percent) of all file entries will be set to this value. [0.0 < sizetol < 1.0]") // .isRequired() .create("sizetol"); Option omd5 = OptionBuilder.withArgName("no|yes").hasArg() .withDescription("[optional; default: yes] should be the md5sum of files determined? no|yes") // .isRequired() .create("md5"); Option oignore = OptionBuilder.withArgName("STRING").hasArgs() .withDescription("[optional] path-pattern that should be ignored when creating the fingerprint") // .isRequired() .create("ignore"); Option oignorefile = OptionBuilder.withArgName("FILE").hasArg().withDescription( "[optional] file with path-patterns (one per line) that should be ignored when creating the fingerprint") // .isRequired() .create("ignorefile"); Option ooutput = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[mandatory; default: <path>/fingerprint.xml] fingerprint file") // .isRequired() .create("output"); Option of = new Option("f", "[optional] force overwrite fingerprint file if it already exists"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(ov); options.addOption(opath); options.addOption(osizetol); options.addOption(omd5); options.addOption(oignore); options.addOption(oignorefile); options.addOption(ooutput); options.addOption(of); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments commandline = parser.parse(options, args); } catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); exiter(); } /*---------------------------- usage/help ----------------------------*/ if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fingerprint", options); System.exit(0); } else if (commandline.hasOption("v")) { System.out.println("web: " + web); System.out.println("author: " + author); System.out.println("version:" + version); System.out.println("date: " + date); System.exit(0); } /*---------------------------- ueberpruefen ob eine schlechte kombination von parametern angegeben wurde ----------------------------*/ String path = ""; String sizetol = ""; boolean md5 = false; Float sizetolFloat = null; String output = ""; java.io.File ignorefile = null; ArrayList<String> ignore = new ArrayList<String>(); if (!(commandline.hasOption("path"))) { System.err.println("setting default for -path=."); path = "."; } else { path = commandline.getOptionValue("path"); } if (!(commandline.hasOption("sizetol"))) { System.err.println("setting default for -sizetol=0.02"); sizetol = "0.02"; sizetolFloat = 0.02F; } else { sizetol = commandline.getOptionValue("sizetol"); sizetolFloat = Float.parseFloat(sizetol); if ((sizetolFloat > 1) || (sizetolFloat < 0)) { System.err.println("use only values >=0.0 and <1.0 for -sizetol"); System.exit(1); } } if (!(commandline.hasOption("md5"))) { System.err.println("setting default for -md5=yes"); md5 = true; } else if (commandline.getOptionValue("md5").equals("no")) { md5 = false; } else if (commandline.getOptionValue("md5").equals("yes")) { md5 = true; } else { System.err.println("use only values no|yes for -md5"); System.exit(1); } if (commandline.hasOption("ignore")) { ignore.addAll(Arrays.asList(commandline.getOptionValues("ignore"))); } if (commandline.hasOption("ignorefile")) { ignorefile = new java.io.File(commandline.getOptionValue("ignorefile")); if (!ignorefile.exists()) { System.err.println("warn: ignore file does not exist: " + ignorefile.getCanonicalPath()); } } if (!(commandline.hasOption("output"))) { System.err.println("setting default for -output=" + path + "/fingerprint.xml"); output = path + "/fingerprint.xml"; } else { output = commandline.getOptionValue("output"); } // wenn output bereits existiert -> abbruch java.io.File outputFile = new File(output); if (outputFile.exists()) { if (commandline.hasOption("f")) { outputFile.delete(); } else { System.err .println("error: output file (" + output + ") already exists. use -f to force overwrite."); System.exit(1); } } // if ( !( commandline.hasOption("output")) ) // { // System.err.println("option -output is mandatory."); // exiter(); // } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- die eigentliche business logic ----------------------------*/ Dir dir = new Dir(); dir.setBasepath(path); dir.setOutfilexml(output); // ignore file in ein Array lesen if ((ignorefile != null) && (ignorefile.exists())) { Scanner sc = new Scanner(ignorefile); while (sc.hasNextLine()) { ignore.add(sc.nextLine()); } sc.close(); } // // autoignore hinzufuegen // String autoIgnoreString = ini.get("autoignore", "autoignore"); // ignoreLines.addAll(Arrays.asList(autoIgnoreString.split(","))); // // debug // System.out.println("ignorefile content:"); // for(String actLine : ignore) // { // System.out.println("line: "+actLine); // } try { dir.genFingerprint(sizetolFloat, md5, ignore); } catch (NullPointerException e) { System.err.println("file/dir does not exist " + path); e.printStackTrace(); exiter(); } catch (IOException e) { e.printStackTrace(); exiter(); } System.out.println("writing to file: " + dir.getOutfilexml()); dir.writeXml(); }
From source file:org.trafodion.rest.zookeeper.ZkUtil.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Usage: ZkUtil {command}"); System.exit(1);//from w w w .j a v a 2 s . c o m } Options opt = new Options(); CommandLine cmd = null; try { cmd = new GnuParser().parse(opt, args); } catch (NullPointerException e) { System.err.println("No args found: " + e); System.exit(1); } catch (ParseException e) { System.err.println("Could not parse: " + e); System.exit(1); } try { String znode = cmd.getArgList().get(0).toString(); ZkClient zkc = new ZkClient(); zkc.connect(); Stat stat = zkc.exists(znode, false); if (stat == null) { System.out.println(""); } else { List<String> znodes = zkc.getChildren(znode, null); zkc.close(); if (znodes.isEmpty()) { System.out.println(""); } else { Scanner scn = new Scanner(znodes.get(0)); scn.useDelimiter(":"); String hostName = scn.next();//host name scn.close(); System.out.println(hostName); } } } catch (Exception e) { System.err.println(e); e.printStackTrace(); System.exit(1); } }
From source file:Main.java
public static long ReadSharedPreferencesLong(Context context, String name, String key, long defaultvalue) { try {/*ww w .jav a 2 s. c om*/ SharedPreferences userInfo = context.getSharedPreferences(name, Context.MODE_WORLD_READABLE); return userInfo.getLong(key, defaultvalue); } catch (NullPointerException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static String ReadSharedPreferencesString(Context context, String name, String key, String defaultvalue) {/*from ww w.j av a2 s .co m*/ try { SharedPreferences userInfo = context.getSharedPreferences(name, Context.MODE_WORLD_READABLE); return userInfo.getString(key, defaultvalue); } catch (NullPointerException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { try {//ww w. jav a 2 s.c o m NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected(); } catch (NullPointerException e) { e.printStackTrace(); return false; } }
From source file:Main.java
/** * @param object/* www .ja v a2 s .c om*/ * @return */ public static final boolean isObjectNull(Object object) { try { if (object != null) { return true; } else { throw new NullPointerException(); } } catch (NullPointerException ne) { ne.printStackTrace(); return false; } }
From source file:Main.java
public static Bitmap getBitmapFromUri(@NonNull Context context, @NonNull Uri uri) throws IOException { InputStream stream = context.getContentResolver().openInputStream(uri); Bitmap rawImage = BitmapFactory.decodeStream(stream); try {//from www . jav a 2 s. c o m stream.close(); } catch (NullPointerException e) { e.printStackTrace(); } return rawImage; }
From source file:Main.java
/** * Utility method to check Internet connection availability * /* ww w . j a va 2 s .co m*/ * @return boolean value indicating the presence of Internet connection * availability */ public static boolean isNetworkAvailable(Activity argActivity) { if (argActivity == null) { return false; } ConnectivityManager connectivityManager; NetworkInfo activeNetworkInfo = null; try { connectivityManager = (ConnectivityManager) argActivity.getSystemService(Context.CONNECTIVITY_SERVICE); activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); } catch (NullPointerException e) { e.printStackTrace(); } return activeNetworkInfo != null; }
From source file:Main.java
/** * Validates an email based on regex -//w ww . j a v a2 s .c om * "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + * "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; * * @param email * String containing email address * @return True if the email is valid; false otherwise. */ public static boolean isEmailValid(String email) { boolean isValid = false; try { // Initialize reg ex for email. String expression = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; CharSequence inputStr = email; // Make the comparison case-insensitive. Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) { isValid = true; } } catch (NullPointerException e) { e.printStackTrace(); } return isValid; }