Android – how to convert strings to class names
•
Android
I'm trying to convert a string to a class name. My code is:
app.actNum = "third.class";
in.close();
//on test
// Intent intent = new Intent(this.context,Class.forName(app.actNum));
Intent dialogIntent = new Intent(getBaseContext(), Class.forName(app.actNum));
But get
get ClassNotFoundException on Class.forName android
resolvent:
When calling class. Forname(), you should use the class name without extension. Therefore, if your class name is test and is in mypackage.tests package, you should use:
Class.forName("mypackage.tests.Test")
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码