getClass() - returns a Class from its name - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

getClass() - returns a Class from its name

Demo Code


import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import android.util.Log;

public class Main{
    private static boolean debug = true;
    /**/* w w  w.j  a v  a  2s  . co m*/
     * getClass() - returns a Class<?> from its name
     * 
     * @param packageName
     *            name of the containing package
     * @param className
     *            name of the class
     */
    public static Class<?> getClass(String packageName, String className) {
        Class<?> c = null;

        try {
            StringBuilder sb = new StringBuilder(packageName);
            sb.append(".");
            sb.append(className);

            c = Class.forName(sb.toString());
        } catch (ClassNotFoundException e) {
            if (debug)
                Log.e(AndroidHack.TAG, "getClass", e);
        }
        return c;
    }
}

Related Tutorials