java.lang.IllegalAccessError:试图访问方法 [英] java.lang.IllegalAccessError: tried to access method

查看:44
本文介绍了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:试图访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆