Gil*_*ing 0 java error-handling runtime-error exception class
因此,我尝试运行一个名为 CountdownTree.java 的特定文件,该文件继承了包 comp2402a4 中的一堆其他文件的函数。
这些都是我的导师提供的起始文件,我应该添加到其中,并且运行这些文件不应该出现任何错误。我使用“javac comp2402a4/CountdownTree.java”编译它,它编译得很好,没有任何问题。但是当我尝试使用“java comp2402a4/CountdownTree.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)
Run Code Online (Sandbox Code Playgroud)
我完全不知道是什么原因造成的,我真的很沮丧,因为我需要运行这个文件,这样我才能开始我的项目。我尝试谷歌搜索但无法弄清楚出了什么问题。对于可能出现的问题,我真的很感激任何帮助。
倒计时树.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);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想尝试运行它,这里有一个包含包中所有文件的文件夹:
https://drive.google.com/drive/folders/1Cu0qNud7-1ACqLvyLahKiVVk0aHcLMEr?usp=sharing
小智 8
我得到了完全相同的错误*做了一些非常愚蠢的事情:
\n\n我尝试将该文件运行为java {main-class}.java. 就这么简单!
相反,请确保将其简单地运行为java {main-class}.
\n*具体来说,我的错误格式与你的一样:
\n\n\n\n\n
{pack.other-class}线程“main”中的异常java.lang.IllegalAccessError:无法从类访问类{pack.main-class}({pack.other-class}位于加载器\'app\'的未命名模块中;{pack.main-class}位于加载器com.sun.tools.javac.launcher.Main$MemoryClassLoader的未命名模块中@29f69090)\xe2\x80\x83\xe2\x80\x83at
\n{pack.main-class}。{who-cares-where}
\n \xe2\x80\x83\xe2\x80\x83at{pack.main-class}。{who-cares-why}
\n \xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83 \xe2\x80\x83\xe2\x80\x83\xe2\x80\x83\xe2\x80\x83 。。。
如果您只编译{main-class}.
所以而不是javac {directory}/{main-class}.java
确保同时编译所有这些,这样交叉引用就不会出现问题:
\xe2\x80\x83\xe2\x80\x83javac {directory}/*.java
我从你的 Google 云端硬盘文件夹中下载,以确保你也遇到此错误,原因只不过是一个愚蠢的命令行混乱。但是,我遇到了一个完全不相关的错误,所以我想您已经更改了文件。然而,我希望这至少对其他人有用,即使不是你!
\n| 归档时间: |
|
| 查看次数: |
7382 次 |
| 最近记录: |