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

查看:3280
本文介绍了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 ?你的系统上有什么旧版本的classes / 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天全站免登陆