Getting a class by its name

If I have an Activity class called TestActivity in my application, there is a way to get its class by its name, as in this example:

Class<?> c = getClassByName("TestActivity"); 
+53
java android class
Apr 12 '12 at 8:23
source share
2 answers

use forName instead.

something like that..

 Class<?> act = Class.forName("com.bla.TestActivity"); 
+109
Apr 12 '12 at 8:26
source share

The Class.forName class has exceptions on it. This is just to expand this problem to solve this problem.

 try { t = Class.forName("com.package.classname"); } catch (Exception ignored){} 
+4
Apr 19 '15 at 22:31
source share



All Articles