如何将字符串转换为类名 [英] how to convert string to class name

查看:121
本文介绍了如何将字符串转换为类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想字符串转换为类的名称。
我的code是:

  app.actNum =third.class;
        附寄();
                //对测试
                   //意向意图=新意图(this.context,的Class.forName(app.actNum));意图dialogIntent =新意图(getBaseContext()的Class.forName(app.actNum));

但得到

 获取了ClassNotFoundException上的android的Class.forName


解决方案

致电时的Class.forName(),你应该使用类名不带扩展名。所以,如果您的被称为测试并在 mypackage.tests ,那么你应该使用:

 的Class.forName(mypackage.tests.Test)

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

解决方案

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")

这篇关于如何将字符串转换为类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆