List of usage examples for java.lang NullPointerException NullPointerException
public NullPointerException(String s)
From source file:Main.java
/** * @param file/*from w w w . j av a 2s.c om*/ * @return */ public static int getNumFilesInFolder(File file) { if (file == null) { throw new NullPointerException("file cannot be null"); } if (!file.exists()) { throw new NullPointerException("file does not exist"); } if (file.isFile()) { throw new ClassCastException("file is not a directory"); } return getSubfilesNumberInFolder(file, false, true); }
From source file:Main.java
/** * Makes a window visible - if invisible - and brings it to front. * * @param window window/* w w w.ja va 2 s . c om*/ */ public static void show(Window window) { if (window == null) { throw new NullPointerException("window == null"); } if (!window.isVisible()) { window.setVisible(true); } window.toFront(); }
From source file:Main.java
public static void runAndWait(Runnable action) { if (action == null) throw new NullPointerException("action"); // run synchronously on JavaFX thread if (Platform.isFxApplicationThread()) { action.run();/*from w w w.j a va 2 s . com*/ return; } // queue on JavaFX thread and wait for completion final CountDownLatch doneLatch = new CountDownLatch(1); Platform.runLater(() -> { try { action.run(); } finally { doneLatch.countDown(); } }); try { doneLatch.await(); } catch (InterruptedException e) { // ignore exception } }
From source file:Main.java
public static NodeList findNodes(Document document, String nodeName) { if (document == null) throw new NullPointerException("Document cannot be null!"); if (nodeName == null) throw new NullPointerException("Nodename cannot be null!"); return document.getElementsByTagName(nodeName); }
From source file:Main.java
private static void setHeader(HttpUriRequest request, Map<String, String> headers) { if (headers == null || headers.size() == 0) { throw new NullPointerException("headers not be null"); }/*from w w w. j a va 2 s . c om*/ for (Entry<String, String> entry : headers.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } }
From source file:Main.java
@Deprecated public static NdefRecord createExternal(String domain, String type, byte[] data) { if (domain == null) throw new NullPointerException("domain is null"); if (type == null) throw new NullPointerException("type is null"); domain = domain.trim().toLowerCase(Locale.US); type = type.trim().toLowerCase(Locale.US); if (domain.length() == 0) throw new IllegalArgumentException("domain is empty"); if (type.length() == 0) throw new IllegalArgumentException("type is empty"); byte[] byteDomain = domain.getBytes(Charset.forName("UTF_8")); byte[] byteType = type.getBytes(Charset.forName("UTF_8")); byte[] b = new byte[byteDomain.length + 1 + byteType.length]; System.arraycopy(byteDomain, 0, b, 0, byteDomain.length); b[byteDomain.length] = ':'; System.arraycopy(byteType, 0, b, byteDomain.length + 1, byteType.length); return new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, b, new byte[0], data); }
From source file:Main.java
public static Element findNode(Element parentNode, String nodeName) { if (parentNode == null) throw new NullPointerException("Parent Node cannot be null!"); if (nodeName == null) throw new NullPointerException("Nodename cannot be null!"); NodeList nodes = parentNode.getElementsByTagName(nodeName); if (nodes == null || nodes.getLength() == 0) return null; if (nodes.getLength() > 1) throw new RuntimeException(nodes.getLength() + " nodes found where only 1 was expected"); return (Element) nodes.item(0); }
From source file:Main.java
public static void playAudio(Context context, int resId) { if (context == null) throw new NullPointerException("context cannot be null"); mediaPlayer = MediaPlayer.create(context, resId); mediaPlayer.start();//from w w w.j a v a2 s .c o m mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); }
From source file:Main.java
public static boolean launchActivity(Context from, Intent intent) { if (from == null) throw new NullPointerException("from == null"); try {/*from ww w. j a v a 2 s . c om*/ from.startActivity(intent); return true; } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } }
From source file:Main.java
protected static void writeXMLwalkTree(Node node, int indent, PrintWriter out) { if (node == null) throw new NullPointerException("Null node passed to writeXMLwalkTree()"); if (node.hasChildNodes()) { if (node instanceof Element) { Element elem = (Element) node; //elem.normalize(); out.print("\n"); for (int j = 0; j < indent; j++) { out.print(" "); }//from w ww. j a va 2s . c om out.print("<" + elem.getTagName()); NamedNodeMap attrs = elem.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr a = (Attr) attrs.item(i); out.print(" " + a.getName() + "=\"" + a.getValue() + "\""); } out.print(">"); NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { writeXMLwalkTree(nl.item(i), indent + 2, out); } // for(int j=0;j<indent;j++) { // out.print(" "); // } out.println("</" + elem.getTagName() + ">"); } } else { if (node instanceof Element) { Element elem = (Element) node; out.print("\n"); for (int j = 0; j < indent; j++) { out.print(" "); } out.print("<" + elem.getTagName()); NamedNodeMap attrs = elem.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr a = (Attr) attrs.item(i); out.print(" " + a.getName() + "=\"" + a.getValue() + "\""); } out.println("/>"); } else if (node instanceof CDATASection) { CDATASection cdata = (CDATASection) node; // for(int j=0;j<indent;j++) { // out.print(" "); // } out.print("<![CDATA[" + cdata.getData() + "]]>"); } else if (node instanceof Text) { Text text = (Text) node; StringBuilder buf = new StringBuilder(text.getData().length()); for (int i = 0; i < text.getData().length(); i++) { if (text.getData().charAt(i) == '\n' || text.getData().charAt(i) == '\r' || text.getData().charAt(i) == ' ' || text.getData().charAt(i) == '\t') { if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ') { buf.append(' '); } } else { buf.append(text.getData().charAt(i)); } } if (buf.length() > 0 && !buf.toString().equals(" ")) { StringBuilder buf2 = new StringBuilder(buf.length() + indent); // for(int j=0;j<indent;j++) { // buf2.append(' '); // } buf2.append(buf.toString()); out.print(buf2); } } } }