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 <K> Map<K, List<?>> copyNullSafeMultiHashMap(Map<? extends K, List<?>> map) {
    if (map == null)
        throw new NullPointerException("map");

    Map<K, List<?>> result = copyNullSafeMutableHashMap(map);
    for (Map.Entry<K, List<?>> entry : result.entrySet()) {
        List<?> value = entry.getValue();
        entry.setValue(Collections.unmodifiableList(new ArrayList<Object>(value)));
    }/* ww w .j a va2s .c  o m*/
    return result;
}

From source file:Main.java

public static <T> T requireNonNull(T o) {
    if (o == null) {
        throw new NullPointerException(o.getClass().getSimpleName() + " must not null");
    }//from   w w  w . j  a  v  a2s  .co m
    return o;
}

From source file:Main.java

/**
 * Method to clarify, that invoking {@code Runnable#run()} is really intented. This also prevents IDEs and other
 * tools from showing warnings./*from ww w  .j  a va2s.  com*/
 *
 * @param runnable
 */
public static void runInThisThread(Runnable runnable) {
    if (runnable == null) {
        throw new NullPointerException("runnable == null");
    }
    runnable.run();
}

From source file:Main.java

public static boolean isValidPhoneNumber(EditText paramEditText) {
    if (paramEditText == null) {
        throw new NullPointerException("EditText can't null");
    }//from w  ww .  j  a v a2  s  . c  o m
    return isValidPhoneNumber(paramEditText.getText().toString());
}

From source file:Main.java

public static boolean batteryPowerIsLow(Context context) {

    if (context == null)
        throw new NullPointerException("context cannot be null");

    final int PowerSaveThreshold = 20;

    int batteryLevel = getCurrentBatteryChargePercentage(context);

    return (batteryLevel <= PowerSaveThreshold) ? true : false;
}

From source file:Main.java

public static void hasPermission() {
    if (mContext == null)
        throw new NullPointerException("you must initialize in appliction to use: CCCoreUtil.init");
    PackageManager pm = mContext.getPackageManager();
    PackageInfo pInfo = null;/* w  w w.j  a v  a 2 s  .co  m*/
    try {
        pInfo = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_PERMISSIONS);
        String[] permissions = pInfo.requestedPermissions;
        for (String permission : permissions) {
            if (TextUtils.equals(mContext.getPackageName() + ".permission." + "WANG_CC_CONG", permission))
                return;
        }
    } catch (Exception e) {
        // TODO: handle exception
        System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:"
                + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />");
        throw new RuntimeException("you must register WANG_CC_CONG permission like:"
                + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />");
    }
    System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:"
            + " <uses-permission android:name=\"PACKAGENAME.permission.WANG_CC_CONG\" />");
    throw new RuntimeException("you must register WANG_CC_CONG permission like:"
            + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />");
}

From source file:Main.java

public static void checkNotNull(Object object, String message) {
    if (TextUtils.isEmpty(message))
        message = "param check failed";
    if (object == null)
        throw new NullPointerException(message);
}

From source file:Main.java

public static <T> List<T> innerJoin(List<List<T>> list, BiFunction<T, T, T> function) {
    if (list == null || function == null) {
        throw new NullPointerException("list or function must not be null");
    }/*from   ww  w . java2  s  . com*/
    if (list.isEmpty()) {
        return Collections.emptyList();
    }
    if (list.size() == 1) {
        return list.get(0);
    }

    List<List<T>> result = innerJoin(list.get(0), list.get(1), function);
    if (list.size() == 2) {
        return merge(result);
    } else {
        for (int i = 2; i < list.size(); i++) {
            List<T> l1 = list.get(i);
            List<List<T>> temp = new ArrayList<>();
            result.stream().forEach(l -> temp.addAll(innerJoin(l, l1, function)));
            result = temp;
        }
        return merge(result);
    }
}

From source file:Main.java

/** Check if the app can be debugged or not */
public static boolean isDebugable(Context context) {
    if (isDebuggable == null) {
        if (context == null) {
            throw new NullPointerException("Context should not be null the first time.");
        }/* w ww  . j av  a  2  s  . c  o  m*/
        isDebuggable = (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
    }
    return isDebuggable;
}

From source file:Main.java

static void checkCollectionForNulls(Collection<?> col) {
    for (Object entry : col) {
        if (entry == null) {
            throw new NullPointerException("collection contains a null entry");
        }// w  w  w . ja v a 2 s. c  o m
    }
}