我在 java_src/classes 的主文件夹中构建了自己的自定义 AWT 类。
每个 java 文件都包含package classes;
顶部的声明。
我还创建了一个名为的示例程序ScreenDemo.java
并将其放置在 java_src/ 文件夹中,以使用自定义 AWT 类而不是java.awt
.
//ScreenDemo.java
import classes.Screen;
class ScreenDemo
{
public static void main(String args[])
{
Screen.init(20,15,3);
}
}
但是当我尝试编译 ScreenDemo.java 时,显示错误
java_src/ScreenDemo.java:1: package classes does not exist
import classes.Screen;
^
java_src/ScreenDemo.java:6: cannot find symbol
symbol : variable Screen
location: class ScreenDemo
Screen.init(20,15,3);
^
2 errors
当我添加路径时,我遇到了这个错误
Exception in thread "main" java.lang.NoClassDefFoundError: ScreenSample (wrong name: classes/ScreenSample)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: ScreenSample. Program will exit.