gpt4 book ai didi

android - 如何将字符串转换为类名

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:36 25 4
gpt4 key购买 nike

我正在尝试将字符串转换为类名。我的代码是:

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

但是得到

  get ClassNotFoundException on Class.forName android

最佳答案

调用 Class.forName() 时,您应该使用不带扩展名的类名。因此,如果您的 名为Test 并且位于package mypackage.tests 中,那么您应该使用:

Class.forName("mypackage.tests.Test")

关于android - 如何将字符串转换为类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11168973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com