Android examples for java.lang.reflect:Method Invoke
invoke Method For Boolean
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static boolean invokeMethodForBoolean(Class invokeClass, String methodName, Object paramObject) { Method method;//from w w w .j a v a 2 s . co m try { method = invokeClass.getDeclaredMethod(methodName); method.setAccessible(true); if ((Boolean) method.invoke(paramObject, null) != null) { return ((Boolean) method.invoke(paramObject, null)) .booleanValue(); } } catch (IllegalArgumentException localIllegalArgumentException) { localIllegalArgumentException.printStackTrace(); return false; } catch (IllegalAccessException localIllegalAccessException) { localIllegalAccessException.printStackTrace(); return false; } catch (InvocationTargetException localInvocationTargetException) { localInvocationTargetException.printStackTrace(); } catch (NoSuchMethodException noSuchMethodException) { noSuchMethodException.printStackTrace(); } return false; } }