Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

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

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static void setField(String paramString, Object paramObject1, Object paramObject2) throws Exception {
    if (TextUtils.isEmpty(paramString))
        throw new RuntimeException("field name can not be empty");
    if (paramObject1 == null)
        throw new RuntimeException("target object can not be null");
    Field localField = paramObject1.getClass().getDeclaredField(paramString);
    if (localField == null)
        throw new RuntimeException("target object: " + paramObject1.getClass().getName()
                + " do not have this field: " + paramString);
    localField.setAccessible(true);//from  w  w  w  .  j av  a  2 s . c  o m
    localField.set(paramObject1, paramObject2);
}

From source file:Main.java

public static final String encode(String content) {
    try {/*from   w w  w  .  ja va 2  s .  c o m*/
        return content == null ? null : URLEncoder.encode(content, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

/**
 * Ensure that the given object is not null, if it is fail the test
 * //w  w w .ja  va 2s.  co  m
 * @param object1
 *            The object to test
 */
public static void assertNotNull(Object object1) {
    if (object1 == null) {
        throw new RuntimeException("TEST FAILS: " + object1 + " must not be null");
    }
}

From source file:Main.java

public static NodeList check1Most(NodeList node, String tag, boolean required) {
    if (node.getLength() == 0) {
        if (!required) {
            return null;
        }/* ww w  . j ava 2s  . c o m*/
        throw new RuntimeException("Tag " + tag + " is required in configuration file");
    } else if (node.getLength() > 1) {
        throw new RuntimeException("Only one tag " + tag + " is required in configuration file");
    }
    return node.item(0).getChildNodes();
}

From source file:Main.java

public static void install(Context context, String apkFilePath) {
    if (context == null) {
        throw new RuntimeException("ApkUtils install apk method and parameter context  == null?");
    }/*from   ww w.  j a va2 s .  c  o m*/

    File file = new File(apkFilePath);

    if (!file.exists()) {
        return;
    }

    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static String getSourcePrinciple(GSSContext context) {
    try {/* w w  w . j  a v  a  2 s  .c o m*/
        return context.getSrcName().toString();
    } catch (GSSException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Class findToken(Class<?> clazz, int tokenIndex) {
    Type superclass = clazz.getGenericSuperclass();
    if (superclass instanceof Class) {
        throw new RuntimeException("Missing type parameter.");
    }//w w  w.ja v  a2 s .  c o  m
    Type entityType = ((ParameterizedType) superclass).getActualTypeArguments()[tokenIndex];
    if (!(entityType instanceof Class)) {
        throw new RuntimeException("Entity type not a class.");
    }
    return (Class) entityType;
}

From source file:Main.java

public static byte[] encodeUcs2UserData(String text) {
    try {/* ww w  .  j av a 2s .  c o m*/
        // UTF-16 Big-Endian, no Byte Order Marker at start
        return text.getBytes("UTF-16BE");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void setFieldValue(Object object, Field field, Object value) {
    try {//  w ww . j  a va  2  s. co  m
        setAccessibleIfNeeded(field);
        field.set(object, value);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

/**
 * Convert uint8 into char( we treat char as uint8)
 * //from   w w  w . j a  v  a 2 s.com
 * @param uint8
 *            the unit8 to be converted
 * @return the byte of the unint8
 */
public static byte convertUint8toByte(char uint8) {
    if (uint8 > Byte.MAX_VALUE - Byte.MIN_VALUE) {
        throw new RuntimeException("Out of Boundary");
    }
    return (byte) uint8;
}