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

/**
 * Drawable convert to Bitmap//  w w  w.j  ava  2s .  c  o m
 */
public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable == null) {

        throw new NullPointerException("drawableToBitmap()-->drawable is null.");
    }

    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;

}

From source file:MainClass.java

static String capitalize(String s) throws NullPointerException, AlreadyCapitalizedException {
    if (s == null) {
        throw new NullPointerException("Your passed a null argument");
    }/*from ww  w.j a  va2  s. co  m*/
    Character firstChar = s.charAt(0);
    if (Character.isUpperCase(firstChar)) {
        throw new AlreadyCapitalizedException();
    }
    String theRest = s.substring(1);
    return firstChar.toString().toUpperCase() + theRest;
}

From source file:Main.java

/**
 * Ensures that the object passed is not null.
 *
 * @param object   The object nullable.// w  w  w .j  a va2 s. c o  m
 * @param property The property.
 */
public static void notNull(@Nullable Object object, @NonNull String property) {
    if (object == null) {
        throw new NullPointerException(property + " == null");
    }
}

From source file:Main.java

public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
    if (reference == null) {
        throw new NullPointerException(String.valueOf(errorMessage));
    } else {/* ww  w  .  ja va 2 s .  co  m*/
        return reference;
    }
}

From source file:Main.java

public static <T> ImmutableList<String> toStrings(Collection<T> input) {

    List<String> result = Lists.newArrayList();

    for (T current : input) {

        if (current == null)
            throw new NullPointerException("Null objects not allowed");

        result.add(current.toString());/*ww  w. j  a  va2 s  .  c om*/
    }

    return ImmutableList.copyOf(result);

}

From source file:Main.java

public static Object getAdditionalInstanceField(Object obj, String key) {
    if (obj == null)
        throw new NullPointerException("object must not be null");
    if (key == null)
        throw new NullPointerException("key must not be null");

    HashMap<String, Object> objectFields;
    synchronized (additionalFields) {
        objectFields = additionalFields.get(obj);
        if (objectFields == null)
            return null;
    }// w w w  . ja v a 2 s . co m

    synchronized (objectFields) {
        return objectFields.get(key);
    }
}

From source file:Main.java

public static Object removeAdditionalInstanceField(Object obj, String key) {
    if (obj == null)
        throw new NullPointerException("object must not be null");
    if (key == null)
        throw new NullPointerException("key must not be null");

    HashMap<String, Object> objectFields;
    synchronized (additionalFields) {
        objectFields = additionalFields.get(obj);
        if (objectFields == null)
            return null;
    }//from  w w  w  .ja v a 2 s .c  o m

    synchronized (objectFields) {
        return objectFields.remove(key);
    }
}

From source file:Main.java

/**
 * Performs some basic check-ups on a given bitmap picture.
 *
 * @param pictureBitmap The bitmap that must be checked
 *//*from www  .j  a  va2s . c  o  m*/
public static void checkBitmap(Bitmap pictureBitmap) {

    if (pictureBitmap == null) {
        throw new NullPointerException("Picture bitmap cannot be null");
    }

    if (pictureBitmap.getWidth() == 0 || pictureBitmap.getHeight() == 0) {
        throw new InvalidParameterException("Picture must have a valid size");
    }
}

From source file:Main.java

public static Object setAdditionalInstanceField(Object obj, String key, Object value) {
    if (obj == null)
        throw new NullPointerException("object must not be null");
    if (key == null)
        throw new NullPointerException("key must not be null");

    HashMap<String, Object> objectFields;
    synchronized (additionalFields) {
        objectFields = additionalFields.get(obj);
        if (objectFields == null) {
            objectFields = new HashMap<String, Object>();
            additionalFields.put(obj, objectFields);
        }/*from   w  ww  . j  a  v a2 s  . com*/
    }

    synchronized (objectFields) {
        return objectFields.put(key, value);
    }
}

From source file:Main.java

/**
 * Join the {@code strings} into one string.
 * //from   w ww.  j  a  v  a  2s. c  om
 * @param strings the string list to join
 * 
 * @return the joined string
 */
public static String join(List<String> strings) {
    if (strings == null) {
        throw new NullPointerException("argument 'strings' cannot be null");
    }
    return join(strings.toArray(new String[strings.size()]));
}