java.lang.IllegalAccessError: tried to access method(java.lang.IllegalAccessError:试图访问方法)
问题描述
我遇到异常,但找不到原因.
I am getting an exception and I can't find the reason of it.
我得到的例外是:
java.lang.IllegalAccessError: 试图访问方法 Connected.getData(Ljava/lang/String;)Ljava/sql/ResultSet;来自B类
java.lang.IllegalAccessError: tried to access method Connected.getData(Ljava/lang/String;)Ljava/sql/ResultSet; from class B
方法是公开的.
public class B
{
public void myMethod()
{
Connected conn = new Connected(); // create a connected class in order to connect to The DB
ResultSet rs = null; // create a result set to get the query result
rs = conn.getData(sql); // do sql query
}
}
public class Connected
{
public ResultSet getData(String sql)
{
ResultSet rs = null;
try
{
prepareConnection();
stmt = conn.createStatement();
stmt.execute(sql);
rs = stmt.getResultSet();
}
catch (SQLException E)
{
System.out.println("Content.getData Error");
E.printStackTrace();
}
return rs;
}
我正在使用 apache tomcat 5.5.12和 JAVA 1.6
i am using apache tomcat 5.5.12 and JAVA 1.6
推荐答案
几乎可以肯定,您在运行时使用的类版本与您期望的版本不同.特别是,运行时类与您编译时所针对的类不同(否则这会导致编译时错误) - 该方法 曾经 是否为 private
?您的系统上是否有旧版本的类/jar?
You are almost certainly using a different version of the class at runtime to the one you expect. In particular, the runtime class would be different to the one you've compiled against (else this would have caused a compile-time error) - has that method ever been private
? Do you have old versions of the classes/jars on your system anywhere?
作为 IllegalAccessError
状态的 javadocs,
As the javadocs for IllegalAccessError
state,
通常,编译器会捕获此错误;如果类的定义发生了不兼容的更改,则此错误只会在运行时发生.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
我肯定会查看您的类路径并检查它是否有任何惊喜.
I'd definitely look at your classpath and check whether it holds any surprises.
这篇关于java.lang.IllegalAccessError:试图访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java.lang.IllegalAccessError:试图访问方法
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01