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:试图访问方法
基础教程推荐
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Maven:无效的目标版本:10 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- JPA惰性列表上的流 2022-01-01
