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(String s) 

Source Link

Document

Constructs a NullPointerException with the specified detail message.

Usage

From source file:Main.java

public static Context getContext() {
    if (sContext != null)
        return sContext;
    throw new NullPointerException("u should init first");
}

From source file:Main.java

public static NdefRecord createTextRecord(String text, Locale locale, boolean encodeInUtf8) {
    if (text == null) {
        throw new NullPointerException("text is MUST require!!");
    }/*  ww  w.  j ava  2 s .com*/
    if (locale == null) {
        throw new NullPointerException("locale is MUST require!!");
    }

    byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII"));

    Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16");
    text = convertToCrlf(text);
    byte[] textBytes = text.getBytes(utfEncoding);

    int utfBit = encodeInUtf8 ? 0 : (1 << 7);
    char status = (char) (utfBit + langBytes.length);

    byte[] data = bytesConcat(new byte[] { (byte) status }, langBytes, textBytes);

    return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);
}

From source file:Main.java

private static <T> void checkIsNull(List<T> collection) {
    if (collection == null) {
        throw new NullPointerException("The supplied collection is null.");
    }//from   ww w  .j av  a  2 s .c  o  m
}

From source file:Main.java

/**
 * Test whether the {@code string} has at least one match by 
 * {@code pattern}.//from   www .ja  v a 2  s  .c  om
 * 
 * @param pattern the regexp
 * @param string the string to test
 * 
 * @return true if at least one match, false if no match
 */
public static boolean test(Pattern pattern, String string) {
    if (pattern == null) {
        throw new NullPointerException("argument 'pattern' cannot be null");
    }
    if (string == null) {
        throw new NullPointerException("argument 'string' cannot be null");
    }
    return pattern.matcher(string).find();
}

From source file:Main.java

/**
 * Determines whether specified type is supported as attributes data or for text-based
 * node property./*from ww  w .  j  ava 2s .c  om*/
 * @param type Type that needs to be checked.
 * @return true if and only if type is supported as attributed type.
 */
public static boolean isSupportedAttributeClass(Class<?> type) {
    if (type == null)
        throw new NullPointerException("Type can not be null.");

    if (type.isPrimitive())
        return true;

    return (supportedAttrTypes.contains(type));
}

From source file:Main.java

/**
 * Converts a string to his binary equivalent.
 *
 * @param text The string that must be converted, cannot be null
 * @return An array of integers representing the binary equivalent
 *//*  www .jav a2  s  .  c  om*/
public static int[] getBinarySequence(String text) {

    if (text == null) {
        throw new NullPointerException("Given text cannot be null");
    }

    char[] textArray = text.toCharArray();
    int[] bitList = new int[textArray.length * UTF8_SIZE];
    int bitListPtr = 0;

    for (char asciiValue : textArray) {

        for (int bitWise = UTF8_SIZE - 1; bitWise >= 0; bitWise--) {
            int tempBit = ((asciiValue & (1 << bitWise)) > 0) ? 1 : 0;

            bitList[bitListPtr] = tempBit;
            bitListPtr++;
        }
    }

    return bitList;
}

From source file:Main.java

/**
 * Creates and returns an unmodifiable List that wraps the given array.
 * Changes to the array will be reflected in the List.
 * @param arr The array to wrap as a List
 * @return an unmodifiable List that wraps the array
 * @throws NullPointerException if the array is null
 *//*from w  w w. j  ava 2  s.  c o m*/
public static List<Double> listFromDoubleArray(final double[] arr) {
    if (arr == null)
        throw new NullPointerException("array cannot be null");
    return new AbstractList<Double>() {
        @Override
        public Double get(int index) {
            return arr[index];
        }

        @Override
        public int size() {
            return arr.length;
        }
    };
}

From source file:Main.java

public static <E> ArrayList<E> copyNullSafeMutableList(Collection<? extends E> list) {
    if (list == null)
        throw new NullPointerException("list");

    ArrayList<E> result = new ArrayList<E>(list);
    for (E element : result) {
        if (element == null)
            throw new NullPointerException("element");
    }//from w ww. j a va 2s  .c  o m
    return result;
}

From source file:Main.java

/****
 * Remove audio file that is existing on the device.
 * //from   w w w  .j  a  v  a2  s  .  co m
 * @param ctx
 *            {@link Context}
 * @param uri
 *            {@link Uri} of the audio file
 * 
 * @throws NullPointerException
 *             if the Uri parameter is null
 * */
public static boolean removeAudio(Context ctx, Uri uri) {

    if (uri == null) {
        throw new NullPointerException("Uri cannot be null");
    }

    return (ctx.getContentResolver().delete(uri, null, null) != 0);
}

From source file:Main.java

/**
 * Returns a list of strings from al collection of arbitrary objects.
 *
 * Uses the <code>toString()</code> operation of every collection element.
 * Null elements set to null in the list.
 *
 * @param  coll collection/*from w ww.jav a 2s .  c  o  m*/
 * @return      list of strings
 */
public static List<String> toStringList(Collection<?> coll) {
    if (coll == null) {
        throw new NullPointerException("coll == null");
    }

    List<String> list = new ArrayList<>(coll.size());

    for (Object o : coll) {
        if (o == null) {
            list.add(null);
        } else {
            list.add(o.toString());
        }
    }

    return list;
}