在线程 "main "中出现异常 java.lang.IllegalAccessError:未能访问类。

问题描述 投票:0回答:1

所以我想运行一个叫CountdownTree.java的特殊文件,这个文件继承了包comp2402a4中其他一堆文件的功能。

这些都是老师给的启动文件,我应该加进去,运行这些文件应该不会出错。我用'javac comp2402a4CountdownTree.java'进行编译,编译得很好,没有问题。但是当我尝试使用'java comp2402a4CountdownTree.java'运行它时,我得到了错误。

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)

我完全不知道是什么原因造成的 我真的很沮丧 因为我需要这个文件来运行,这样我才能启动我的项目。我试着上网查了一下,但不知道哪里出了问题。我真的很感激任何关于问题所在的帮助。

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);
    }
}

这里有一个文件夹,里面有所有的文件 如果你想试着运行它的话。

https:/drive.google.comdrivefolders1Cu0qNud7-1ACqLvyLahKiVVk0aHcLMEr?usp=共享。

java class exception error-handling runtime-error
1个回答
0
投票

实际问题

我做了一些非常愚蠢的事情,也得到了这个完全相同的错误*。

我试着将文件以 java {main-class}.java. 就这么简单!

相反,一定要简单地运行它为 java {main-class}.

*具体来说,我的错误格式和你一样。

"main "线程中出现异常 java.lang.IllegalAccessError: failed to access class. {pack.other-class} 从类 {pack.main-class} ({pack.other-class} 在加载器的未命名模块 "app "中。{pack.main-class} 在加载器的未命名模块中 com.sun.tools.javac.launcher.Main$MemoryClassLoader @29f69090)

  在 {pack.main-class}.{who-cares-where}   在 {pack.main-class}.{who-cares-why}              . . .

额外建议

如果你只编译了你的 {main-class}.

所以,与其说是 javac {directory}/{main-class}.java

一定要同时编译,这样在交叉引用时就不会出现问题。   javac {directory}/*.java

OP Specific

我从你的Google Drive文件夹中下载,以确定你也是由于一个愚蠢的命令行故障而出现这个错误。然而,我得到了一个完全不相关的错误,所以我想你已经改变了文件。不过,我希望这至少能帮助到其他人,如果不是你的话。

© www.soinside.com 2019 - 2024. All rights reserved.