线程“ main”中的异常java.lang.IllegalAccessError:无法访问类 [英] Exception in thread "main" java.lang.IllegalAccessError: failed to access class

查看:1298
本文介绍了线程“ main”中的异常java.lang.IllegalAccessError:无法访问类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图运行一个名为CountdownTree.java的文件,该文件从comp2402a4包中的许多其他文件继承函数。

So I'm trying to run a particular file called CountdownTree.java that inherits functions from a bunch of other files in the package comp2402a4.

这些都已经开始了我应该添加给我的讲师的文件,运行这些文件应该没有任何错误。我使用 javac comp2402a4 / CountdownTree.java对其进行了编译,并且编译良好,没有任何问题。但是,当我尝试使用'java comp2402a4 / CountdownTree.java'运行它时,出现错误:

These were all starting files given by my instructor that I'm supposed to add to, and there shouldn't be any errors running these files. I compiled it using 'javac comp2402a4/CountdownTree.java' and it compiled fine with no problems. But when I try to run it using 'java comp2402a4/CountdownTree.java', I get the error:

Exception in thread "main" java.lang.IllegalAccessError: failed to access class 
comp2402a4.DefaultComparator from class comp2402a4.CountdownTree (comp2402a4.DefaultComparator is in 
unnamed module of loader 'app'; comp2402a4.CountdownTree is in unnamed module of loader 
com.sun.tools.javac.launcher.Main$MemoryClassLoader @21507a04)
        at comp2402a4.CountdownTree.<init>(CountdownTree.java:26)
        at comp2402a4.CountdownTree.main(CountdownTree.java:53)

我绝对不知道是什么原因造成的,我真的沮丧,因为我需要运行该文件,以便可以启动我的项目。我尝试使用Google搜索,但无法找出问题所在。对于可能存在的问题,我将不胜感激。

I have absolutely no idea what's causing this and I'm really frusterated because I need this file to run so I can start my project. I tried googling but couldn't figure out what's wrong. I would really appreciate any help as to what might be the problem.

CountdownTree.java:

CountdownTree.java:

package comp2402a4;

import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;

/**
* An unfinished implementation of an Countdown tree (for exercises)
* @author morin
*
* @param <T>
*/
public class CountdownTree<T> extends
BinarySearchTree<CountdownTree.Node<T>, T> implements SSet<T> {

    // countdown delay factor
    double d;

    public static class Node<T> extends BSTNode<Node<T>,T> {
        int timer;  // the height of the node
    }

    public CountdownTree(double d) {
        this.d = d;
        sampleNode = new Node<T>();
        c = new DefaultComparator<T>();
    }

    public boolean add(T x) {
        Node<T> u = new Node<T>();
        u.timer = (int)Math.ceil(d);
        u.x = x;
        if (super.add(u)) {
            // add some code here
            return true;
        }
        return false;
    }

    public void splice(Node<T> u) {
        Node<T> w = u.parent;
        super.splice(u);
        // add some code here (we just removed u from the tree)
    }

    protected void explode(Node<T> u) {
        // Write this code to explode u
        // Make sure to update u.parent and/or r (the tree root) as appropriate
    }

    // Here is some test code you can use
    public static void main(String[] args) {
        Testum.sortedSetSanityTests(new SortedSSet<Integer>(new CountdownTree<Integer>(1)), 1000);
        Testum.sortedSetSanityTests(new SortedSSet<Integer>(new CountdownTree<Integer>(2.5)), 1000);
        Testum.sortedSetSanityTests(new SortedSSet<Integer>(new CountdownTree<Integer>(0.5)), 1000);

        java.util.List<SortedSet<Integer>> ell = new java.util.ArrayList<SortedSet<Integer>>();
        ell.add(new java.util.TreeSet<Integer>());
        ell.add(new SortedSSet<Integer>(new CountdownTree<Integer>(1)));
        ell.add(new SortedSSet<Integer>(new CountdownTree<Integer>(2.5)));
        ell.add(new SortedSSet<Integer>(new CountdownTree<Integer>(0.5)));
        Testum.sortedSetSpeedTests(ell, 1000000);
    }
}

这里是一个包含所有文件包的文件夹,如果您想尝试运行它:

Here's a folder with all the files in the package if you'd like to try running it:

https://drive.google.com/drive/folders/1Cu0qNud7-1ACqLvyLahKiVVk0aHcLMEr?usp=sharing

推荐答案

实际问题



我在做一些非常愚蠢的事情时遇到了同样的错误*:

Actual Issue

I got this exact same error* doing something very silly:

我尝试将文件运行为 java {main-class} .java 。如此简单!

I tried to run the file as java {main-class}.java. That simple!

相反,请确保将其简单地运行为 java {main-class}

Instead, be sure to run it simply as java {main-class}.



*特别是,我遇到的错误格式,例如您的错误格式:


*Specifically, the error format I had, like yours:


线程主中的异常java.lang.IllegalAccessError:无法从类<$访问类 {pack.other-class} c $ c> {pack.main-class} ( {pack.other-class} 在加载程序'app'的未命名模块中; {pack.main-class} 在加载器com.sun.tools.javac.launcher.Main $ MemoryClassLoader @ 29f69090的未命名模块中)

Exception in thread "main" java.lang.IllegalAccessError: failed to access class {pack.other-class} from class {pack.main-class} ({pack.other-class} is in unnamed module of loader 'app'; {pack.main-class} is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @29f69090)

at {pack.main-class} {who-cares-where}

at {pack.main-class} {who-cares-why}

strong 。 。 。


如果只编译 {main-class,则在同一问题上也会出现类似的烦人错误,即无法访问同一目录中的软件包}

因此代替 javac {directory} / {main-class} .java

So instead of javac {directory}/{main-class}.java

请确保同时编译所有文件,因此交叉引用没有问题:
javac {directory} / *。java

Be sure to compile all of them at the same time, so there's no issue in cross-referencing:
  javac {directory}/*.java


我是从您的Google云端硬盘文件夹中下载的,以确保您也由于无聊的命令而收到此错误行snafu。但是,我遇到了一个完全不相关的错误,因此我想您已经更改了文件。但是,我希望这至少可以为其他人服务,如果没有的话!

I downloaded from your Google Drive folder, to make sure you were also getting this error due to nothing more than a silly command-line snafu. However, I got a completely unrelated error, so I imagine you've since changed the files. However, I hope this at least serves someone else, if not you!

这篇关于线程“ main”中的异常java.lang.IllegalAccessError:无法访问类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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