vendredi 14 décembre 2018

Java reflection - Android classes not found

I am trying to run reflection to check if some android class exists in Java ( such as Toast ). I am running it from my Command line using this code:

String [] packages = new String[] {"java.lang.",
    "android.widget.",
    "android.util.",
    "android.app.",
    "android.view.",
    "android.content."};
for (int i = 0; i < packages.length; i++){
    String package_name = packages[i];
    try {
        Class<?> clazz = Class.forName(package_name + "Toast");
        System.out.println("class Exists");
        return clazz;
    }
    catch (ClassNotFoundException e){
        System.out.println("class " + package_name + "Toast doesnt exists");
    }
}

However, I get the output: class android.widget.Toast doesn't exists ( but I know it does this is where the class is at) any ideas?





Aucun commentaire:

Enregistrer un commentaire