我上课了
public Class Foobar{
public void methodA();
}
Run Code Online (Sandbox Code Playgroud)
现在我在另一个类中有一个方法
public static final void callFooBar(){
Foobar foobar = new Foobar();
foobar.methodA(); <-- error here
}
Error: Exception in thread "main" java.lang.IllegalAccessError: tried to access method package.FooBar.methodA([Ljava/lang/String;)V from class package.mainclass
Run Code Online (Sandbox Code Playgroud)
任何建议(抱歉这里是新手)
首先,区分大小写.您的错误表明FooBar()您的班级被命名Foobar()
也许您在运行时使用的是不同版本的类,而不是您期望的类.特别是,运行时类与您编译的运行时类不同(否则会导致编译时错误) - 该方法是否曾被私有?您的系统上是否有旧版本的课程/罐子?
作为IllegalAccessError国家的javadocs ,
通常,编译器会捕获此错误; 如果类的定义发生了不兼容的更改,则此错误只能在运行时发生.
我肯定会看看你的类路径并检查它是否有任何意外.
| 归档时间: |
|
| 查看次数: |
3673 次 |
| 最近记录: |