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 <E> LinkedHashSet<E> newLinkedHashSet(E... elements) {
    if (elements == null) {
        throw new NullPointerException();
    }//  www. ja  v a  2  s. c om
    return new LinkedHashSet<E>(Arrays.asList(elements));
}

From source file:Main.java

public static int readInputStream(InputStream input, byte[] buffer, int offset, int length) throws Exception {
    int n, o;/*from  w ww  . ja v  a  2 s .c o  m*/

    if (buffer == null)
        throw new NullPointerException();
    if (offset < 0 || length < 0 || offset + length > buffer.length)
        throw new IndexOutOfBoundsException();
    if (length == 0)
        return 0;

    if ((n = input.read(buffer, offset++, 1)) < 0)
        return -1;

    if (--length > 0 && (o = input.available()) > 0) {
        n += input.read(buffer, offset, o > length ? length : o);
    }

    return n;
}

From source file:Main.java

public static <E> ArrayList<E> newArrayList(Iterable<E> iterable) {
    if (iterable == null) {
        throw new NullPointerException();
    }/* ww w.  j a v  a 2  s  .  c  o  m*/
    ArrayList<E> list = new ArrayList<E>();
    for (Iterator<E> i = iterable.iterator(); i.hasNext();) {
        list.add(i.next());
    }
    return list;
}

From source file:Main.java

/**
 * @param object//from ww  w  .  java 2  s  .  c o m
 * @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 boolean isFirstUpperCase(String target) throws NullPointerException {
    if (target == null)
        throw new NullPointerException();
    final char c = target.charAt(0);
    for (int i = 0, size = UpperCases.length; i < size; i++) {
        if (UpperCases[i] == c) {
            return true;
        }/*from   w  w  w.j  a  va 2 s  .  com*/
    }
    return false;
}

From source file:Main.java

public static void appendElementText(Element parentElement, String elementName, String elementValue) {

    if (parentElement == null || elementName == null || elementValue == null)
        throw new NullPointerException();

    Element childElement = parentElement.getOwnerDocument().createElement(elementName);
    setTextContent(childElement, elementValue);
    parentElement.appendChild(childElement);
}

From source file:Main.java

public static <T> T checkNotNull(T value) {
    if (value == null) {
        throw new NullPointerException();
    }// ww w .j  a  v  a  2  s  .  c o m
    return value;
}

From source file:Main.java

public static String getElementText(Element parentElement, String elementName) {

    if (parentElement == null || elementName == null)
        throw new NullPointerException();

    Element childElement = (Element) parentElement.getElementsByTagName(elementName).item(0);
    return getTextContent(childElement);
}

From source file:Main.java

public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) {

    if (fragmentManager == null || fragment == null) {
        throw new NullPointerException();
    }//w w w  .  ja  va2  s  .c  om

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(frameId, fragment);
    transaction.commit();
}

From source file:Main.java

/**
 * Ensures that an object reference passed as a parameter to the calling method is not null.
 *
 * @param reference an object reference/*ww  w .  j a  v  a  2 s  .com*/
 * @return the non-null reference that was validated
 * @throws NullPointerException if {@code reference} is null
 */
public static <T> T checkNotNull(final T reference) {
    if (reference == null) {
        throw new NullPointerException();
    }
    return reference;
}