Example usage for java.lang SecurityException printStackTrace

List of usage examples for java.lang SecurityException printStackTrace

Introduction

In this page you can find the example usage for java.lang SecurityException 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

@SuppressWarnings("rawtypes")
public static Field getDeclaredField(Class clazz, String name) {
    try {/* ww  w .j a va  2 s.  co  m*/
        return clazz.getDeclaredField(name);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Constructor<?> getConstructor(Class<?> targetClass, Class<?>... types) {
    if (targetClass == null || types == null)
        return null;
    try {/*from   w w  w .jav a 2s .c om*/
        return targetClass.getConstructor(types);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Method getMethod(Class<?> targetClass, String name, Class<?>... parameterTypes) {
    if (targetClass == null || TextUtils.isEmpty(name))
        return null;
    try {//from w w w .  j  a v  a 2s .  c o m
        return targetClass.getMethod(name, parameterTypes);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Field getField(Class<?> targetClass, String name) {
    if (targetClass == null || TextUtils.isEmpty(name))
        return null;
    try {//from ww  w .j  a  v  a2s .co m
        return targetClass.getField(name);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static Object getFieldObject(Object target, Class clazz, String fieldName) {
    try {//from  w w w.j a  v  a 2  s.  c om
        Field field = clazz.getDeclaredField(fieldName);
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
        return field.get(target);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;

}

From source file:Main.java

private final static Field getField(String name) {
    Field field = null;/*  w  w w . j av a2s  .c  o m*/
    try {
        field = sCurrentClass.getDeclaredField(name);
        field.setAccessible(true);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        //         e.printStackTrace();
    }

    return field;
}

From source file:Main.java

public static Object invokeMethod(Object target, Class clazz, String methodName, Class[] paramTypes,
        Object[] paramValues) {//from w  w  w .j a v  a2 s  .c o m
    try {
        Method method = clazz.getDeclaredMethod(methodName, paramTypes);
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        return method.invoke(target, paramValues);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Field getFieldByName(Class<?> clazz, String fieldName) {
    Field field = null;/*w  w w. java2  s  .  c  o  m*/
    if (fieldName != null) {
        try {
            field = clazz.getDeclaredField(fieldName);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    return field;
}

From source file:Main.java

static Object getInstanceByClass(Class<?> claz) {
    try {//from w  w w .j  a  va  2 s.  co m
        if (claz == Long.class || claz == Integer.class || claz == Short.class || claz == Double.class
                || claz == Float.class || claz == Byte.class)
            return claz.getConstructor(String.class).newInstance("0");
        else
            return claz.newInstance();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static boolean deleteFile(String fileName) {
    boolean status;
    SecurityManager checker = new SecurityManager();

    if (!fileName.equals("")) {

        File path = Environment.getExternalStorageDirectory();
        File newPath = new File(path.toString() + fileName);
        checker.checkDelete(newPath.toString());
        if (newPath.isFile()) {
            try {
                Log.i("DirectoryManager deleteFile", fileName);
                newPath.delete();//from ww w  .  j  ava2s  .  c  o  m
                status = true;
            } catch (SecurityException se) {
                se.printStackTrace();
                status = false;
            }
        } else
            status = false;
    } else
        status = false;
    return status;
}