出于某种奇怪的原因,我最近在 Eclipse 中处理 Android 程序时遇到了错误。昨晚还好好的,今天就报错了。这是有问题的代码:
Class ourClass = Class.forName("com.example.exampleone" + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
对于第一行,我收到错误:
The method forName(String) is undefined for the type Class
对于第二行,我收到错误:
The constructor Intent(Menu, Class) is undefined
代码一直很好,直到今天,突然开始说有一个错误
最佳答案
一种可能性:您可能创建了自己的类,名为Class
。这肯定会导致这两个错误。检查这一点的一种方法(不仅仅是试图找到有问题的类)是将第一行更改为:
java.lang.Class ourClass = java.lang.Class.forName(
"com.example.exampleone" + cheese);
关于java - 奇怪的未定义方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8673913/