Example usage for java.lang NullPointerException NullPointerException

List of usage examples for java.lang NullPointerException NullPointerException

Introduction

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

Prototype

public NullPointerException() 

Source Link

Document

Constructs a NullPointerException with no detail message.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread thread = new Thread() {
        public void run() {
            throw new NullPointerException();
        }//  w  w w.  j a  va  2s  . c  o  m
    };
    thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread arg0, Throwable arg1) {
            arg1.printStackTrace();
        }
    });
    thread.start();
}

From source file:Main.java

public static <T> T checkNotNull(T obj) {
    if (obj == null)
        throw new NullPointerException();

    return obj;//  ww  w.ja  v a2 s.c om
}

From source file:Main.java

private static <T> void checkParam(T param) {
    if (param == null) {
        throw new NullPointerException();
    }//from w  ww  .ja  v  a2s  .  com
}

From source file:Main.java

public static byte[] unicode(String s) {
    if (s == null) {
        throw new NullPointerException();
    }/*w  w  w. j  a  va2 s . c o  m*/

    int len = s.length();
    byte[] ret = new byte[len * 2];
    int a, b, c;
    for (int i = 0; i < len; i++) {
        c = s.charAt(i);
        a = c >> 8;// high bits
        b = c & 0xFF;// low bits
        if (a < 0) {
            a += 0xFF;
        }
        if (b < 0) {
            b += 0xFF;
        }
        ret[i * 2] = (byte) b;
        ret[i * 2 + 1] = (byte) a;
    }
    return ret;
}

From source file:Main.java

public static String authEncode(String src) {
    if (TextUtils.isEmpty(src)) {
        throw new NullPointerException();
    }//from  w w w . j ava 2 s  .co m
    byte[] buf = src.getBytes();
    for (int i = 0; i < buf.length; i++) {
        buf[i] ^= (i + 0x40);
    }
    return new String(buf);
}

From source file:Main.java

public static <T> T checkNotNull(T reference) {
    if (reference == null) {
        throw new NullPointerException();
    } else {//from   w  w w . j  a  v  a  2  s  . co m
        return reference;
    }
}

From source file:Main.java

public static int Cardinality(Object obj, Collection coll) {
    if (coll == null) {
        throw new NullPointerException();
    }//from   www  . j  av  a  2  s. c  om
    if (obj == null) {
        throw new NullPointerException();
    }
    for (Object o : coll) {
        if (o.equals(obj)) {
            total++;
        }
    }
    return total;
}

From source file:Main.java

public static String getTextContent(Node node) {

    if (node == null)
        throw new NullPointerException();

    String textContent;/*from   w  w  w  .  ja  va2  s  .  com*/

    textContent = node.getTextContent();
    if (textContent != null)
        return xmlDecode(textContent);

    NodeList childNodes = node.getChildNodes();
    if (childNodes.getLength() > 0 && childNodes.item(0) instanceof Text)
        textContent = node.getNodeValue();
    if (textContent != null)
        return xmlDecode(textContent);

    return "";
}

From source file:Main.java

public static <T1 extends Comparable<T2>, T2> int binarySearch(final List<T2> lst, final T1 elem) {
    if (lst == null || elem == null)
        throw new NullPointerException();

    int low = 0;/*from  w w w  .  ja  v a 2s. co m*/
    int high = lst.size() - 1;

    while (low <= high) {
        final int mid = low + (high - low) / 2;

        final T2 testElem = lst.get(mid);
        final int comparison = elem.compareTo(testElem);

        if (comparison == 0)
            return mid;
        if (comparison > 0) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }

    return -(low + 1);
}

From source file:Main.java

public static Activity getCurActivity() {
    if (current_activity == null) {
        // not initialized
        throw new NullPointerException();
    }/*from   w w w  . j  ava 2 s  .  co m*/
    return current_activity;
}