Example usage for java.lang ClassNotFoundException printStackTrace

List of usage examples for java.lang ClassNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static Object loadClass(Context context, String path) {
    try {/*w w w .ja  v  a  2s  . com*/
        String dexPath = context.getApplicationInfo().sourceDir;
        PathClassLoader pathClassLoader = new PathClassLoader(dexPath, context.getClassLoader());
        Class<?> c = Class.forName(path, true, pathClassLoader);
        Object ret = c.newInstance();
        return ret;
    } catch (InstantiationException ex1) {
        ex1.printStackTrace();
    } catch (IllegalAccessException ex2) {
        ex2.printStackTrace();
    } catch (ClassNotFoundException ex3) {
        ex3.printStackTrace();
    }

    return null;
}

From source file:Main.java

static boolean isTypeAssignableFrom(Type type, Class<?> clazz) {
    Class<?> aClazz = null;
    try {/*w  w  w. java 2 s  .  co  m*/
        aClazz = getClass(type);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (aClazz != null && clazz.isAssignableFrom(aClazz)) {
        return true;
    }
    return false;
}

From source file:Main.java

public static void setNimbusLookAndFeel() {

    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            try {
                UIManager.setLookAndFeel(info.getClassName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();/*from   ww w .  ja v a2 s  . c  o  m*/
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
            break;
        }
    }
}

From source file:Main.java

/**
 * getChildClass//  w  ww .  j a v a2  s.com
 *
 * @param field List<Child> children type
 * @return thie child class
 */
public static Class getChildClass(Field field) {
    Type t = field.getGenericType();
    Type actualType = ((ParameterizedType) t).getActualTypeArguments()[0];
    Class subclass = null;
    try {
        subclass = Class.forName(actualType.getClass().getName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.out.println(subclass.getSimpleName());
    return subclass;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static String getDeviceSerial() {
    String serial = "null";
    try {/*from ww  w . jav a 2s .  c om*/
        Class clazz = Class.forName("android.os.Build");
        Class paraTypes = Class.forName("java.lang.String");
        Method method = clazz.getDeclaredMethod("getString", paraTypes);
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        serial = (String) method.invoke(new Build(), "ro.serialno");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return serial;
}

From source file:Main.java

public static void chmod(String filename, int permissions) {
    Class<?> fileUtils = null;
    try {//from   w  w  w  . j a  va  2s. c o m
        fileUtils = Class.forName("android.os.FileUtils");
    } catch (ClassNotFoundException e1) {
        e1.printStackTrace();
    }
    Method setPermissions = null;
    int a;
    try {
        setPermissions = fileUtils.getMethod("setPermissions",
                new Class[] { String.class, int.class, int.class, int.class });
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    try {
        a = (Integer) setPermissions.invoke(null, filename, permissions, -1, -1);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static List<Class> findClasses(File directory, String packageName) {
    List<Class> classes = new ArrayList<Class>();
    if (!directory.exists()) {
        return classes;
    }/*w w w.j a v  a2 s.c o m*/
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class")) {
            try {
                classes.add(Class
                        .forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return classes;
}

From source file:Main.java

/**
 * Get the API redirect uri//from  w  w  w .  j  a  v  a 2 s.  c  o m
 *
 * @param cloudApi type of cloud account
 * @return Uri
 */
public static Uri getRedirectUri(String cloudApi) {
    // use reflection for flexibility
    try {
        Class clazz = Class.forName(cloudApi);
        Field redirectUrl = clazz.getField("REDIRECT_URL");
        return Uri.parse((String) redirectUrl.get(null));
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static void setLookAndFeel() {
    if (UIManager.getLookAndFeel().getID().equals("Aqua")) { //$NON-NLS-1$
        SPINNERHEIGHT = 20;//ww  w  .  ja v a  2 s. c  o  m
    } else { // try to use Nimbus unless on Mac Os
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); //$NON-NLS-1$
        } catch (Exception e) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            } catch (InstantiationException e1) {
                e1.printStackTrace();
            } catch (IllegalAccessException e1) {
                e1.printStackTrace();
            } catch (UnsupportedLookAndFeelException e1) {
                e1.printStackTrace();
            }
        }
    }
}

From source file:Main.java

static boolean isGenericTypeAssignableFrom(ParameterizedType type, Class<?> clazz) {
    Type[] actualTypes = type.getActualTypeArguments();
    for (Type actualType : actualTypes) {
        Class<?> aClazz = null;
        try {//  ww w. j  a  va 2  s .  c  o  m
            aClazz = getClass(actualType);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        if (aClazz != null && clazz.isAssignableFrom(aClazz)) {
            return true;
        }
    }
    return false;
}