List of usage examples for java.lang NoSuchMethodException printStackTrace
public void printStackTrace()
From source file:MethodTrouble.java
public static void main(String... args) { try {//ww w .ja va2 s. co m String mName = args[0]; Class cArg = Class.forName(args[1]); Class<?> c = (new MethodTrouble<Integer>()).getClass(); Method m = c.getMethod(mName, cArg); System.out.format("Found:%n %s%n", m.toGenericString()); // production code should handle these exceptions more gracefully } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static boolean hasExtSdcard(Context context) { String[] paths;//from www . j a v a 2 s . c o m StorageManager service = (StorageManager) context.getSystemService(Activity.STORAGE_SERVICE); try { Method mMethod = service.getClass().getMethod("getVolumePaths"); paths = (String[]) mMethod.invoke(service); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static void setRefreshing(SwipeRefreshLayout refreshLayout, boolean refreshing, boolean notify) { Class<? extends SwipeRefreshLayout> refreshLayoutClass = refreshLayout.getClass(); if (refreshLayoutClass != null) { try {//from w ww . jav a 2 s.c o m Method setRefreshing = refreshLayoutClass.getDeclaredMethod("setRefreshing", boolean.class, boolean.class); setRefreshing.setAccessible(true); setRefreshing.invoke(refreshLayout, refreshing, notify); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } }
From source file:Main.java
public static Object newHandlerInstance(String clzPath, Class<?>[] parameterTypes, Object[] args) { try {/*from w ww .ja va 2 s .c o m*/ Class<?> clz = Class.forName(clzPath); Constructor<?> constructor = clz.getConstructor(parameterTypes); return constructor.newInstance(args); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
static public <T> T callMethodWithNoArgs(Object obj, String methodName) { Class<?> clazz = obj.getClass(); try {//from w ww. java 2 s. co m Method method = clazz.getMethod(methodName); return (T) method.invoke(obj); } catch (NoSuchMethodException e) { e.printStackTrace(); throw new RuntimeException("NoSuchMethodException " + methodName); } catch (InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException("InvocationTargetException " + methodName); } catch (IllegalAccessException e) { e.printStackTrace(); throw new RuntimeException("IllegalAccessException " + methodName); } }
From source file:Main.java
public static void chmod(String filename, int permissions) { Class<?> fileUtils = null; try {// w w w . j av a2 s. 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
public static Object invokeMethod(Object handler, String callback, Class<?>[] cls, Object... params) { if (handler == null || callback == null) return null; Method method = null;/*from ww w . ja v a 2s . c o m*/ try { if (cls == null) cls = new Class[0]; method = handler.getClass().getMethod(callback, cls); return method.invoke(handler, params); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static List<String> collectAsString(List<? extends Object> objects, String fieldName) { List<String> stringsAsAttribute = new ArrayList<String>(); String getterName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1, fieldName.length()); try {/*ww w .ja v a 2s .c o m*/ for (Object object : objects) { Method getterMethod = object.getClass().getMethod(getterName); Object result = getterMethod.invoke(object); stringsAsAttribute.add(result.toString()); } } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return stringsAsAttribute; }
From source file:reflect.TestCopy.java
private static void copy2(Object src, Object dest) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class srcClass = src.getClass(); Class destClass = dest.getClass(); Method[] srcMs = srcClass.getDeclaredMethods(); for (Method srcM : srcMs) { //??/* ww w .j a v a2 s . com*/ String methodName = srcM.getName(); if (methodName.startsWith("get")) { //srcsrcM? Object value = srcM.invoke(src, new Object[] {}); //methodName.substring(3)?? String destSetName = "set" + methodName.substring(3); try { //destClass?getMethod ?? ??? //? ?????value? Method destMethod = destClass.getMethod(destSetName, new Class[] { value.getClass() }); //?? dest value? destMethod.invoke(dest, new Object[] { value }); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } } } }
From source file:Main.java
/** * see http://habrahabr.ru/post/144547///from ww w . ja v a 2 s .c om */ public static BluetoothSocket createRfcommSocket(BluetoothDevice device) { BluetoothSocket tmp = null; try { Class class1 = device.getClass(); Class aclass[] = new Class[1]; aclass[0] = Integer.TYPE; Method method = class1.getMethod("createRfcommSocket", aclass); Object aobj[] = new Object[1]; aobj[0] = Integer.valueOf(1); tmp = (BluetoothSocket) method.invoke(device, aobj); } catch (NoSuchMethodException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } catch (InvocationTargetException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } catch (IllegalAccessException e) { e.printStackTrace(); if (D) Log.e(TAG, "createRfcommSocket() failed", e); } return tmp; }