Exception in thread "main" java.lang.SecurityException: Prohibited package name: java
at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:889)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1005)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:801)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:654)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:551)
答案 0 :(得分:4)
更改您的包裹名称。
You can't have java as a package name as it's prohibited.
所以如果你有这个:
package java;
public class Helloworld {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a + b);
}
}
例如,它需要是这样的:
package mypackagenamethatisnotthewordjava;
public class Helloworld {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a + b);
}
}
还要确保重命名代码所在的文件夹以匹配类中声明的包名称。