Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert string to class name

Tags:

android

class

I am trying to convert string to 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
like image 308
Vitaly Menchikovsky Avatar asked Nov 28 '22 07:11

Vitaly Menchikovsky


1 Answers

When calling Class.forName(), you should use the class's name without the extension. So if your class is calledTest and is in the package mypackage.tests, then you should use:

Class.forName("mypackage.tests.Test")
like image 147
Adel Boutros Avatar answered Dec 17 '22 04:12

Adel Boutros