Android examples for java.lang.reflect:Class
Check if a class Can Be Loaded
import android.content.Context; import android.util.Log; import java.lang.reflect.Method; public class Main{ private static final String TAG = Util.getTag(ReflectionHelper.class); public static boolean classCanBeLoaded(Context context, String packageAndClassName) { try {//from w ww. j ava 2 s .c o m context.getClassLoader().loadClass(packageAndClassName); return true; } catch (ClassNotFoundException e) { return false; } } private static Class loadClass(Context context, String packageAndClassName) throws ReflectionHelperException { try { return context.getClassLoader().loadClass(packageAndClassName); } catch (ClassNotFoundException e) { Log.e(TAG, "Could not load class", e); throw new ReflectionHelperException(e); } } }