线程“main"中的异常java.lang.SecurityException:禁止的包名:java.lang [英] Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.lang

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

问题描述

我是 Java 新手,我有一个程序返回以下错误,我完全无法弄清楚.我用谷歌搜索了一切.你们能帮我吗?

I'm a newbie at Java and I have a program that is returning the following error that I am completely unable to figure out. I googled and everything. Could you guys help me?

package java.lang;
public class S1 {
public static void main(String[] args) {
    for (int i=1;i<=1000;i++)
        {
            String str = "1" +i;
        }
    }
}

 

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.lang
    at java.lang.ClassLoader.preDefineClass(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

我正在使用 Eclipse,并且正在使用文件 S1.java 中的包 java.lang.

I am using Eclipse, and am working with the package java.lang in the file S1.java.

推荐答案

您不能将新内容放入 java.lang 包中.它由语言保留,因为它是核心 Java 内容所在的位置.事实上,java.lang 包中的所有内容在默认情况下都是隐式导入的,在任何一段 Java 代码中.

You can't place new content into the java.lang package. It's reserved by the language because that's where the core Java content already resides. In fact, everything within the java.lang package is implicitly imported by default, in any piece of Java code.

它包含对 Java 编程语言的设计至关重要的类".(来自文档).由于用户定义的类根据定义不能对语言的设计起到关键作用,因此禁止将内容放在那里.允许用户将代码放在 java.lang 包中也将是一个问题,因为这会将在那里定义的任何包域内容暴露给用户.

It contains "classes that are fundamental to the design of the Java programming language." (from the docs). Since user-defined classes cannot, by definition, be critical to the design of the language, you are forbidden from putting content there. Allowing users to put code within the java.lang package would also be a problem because that would expose any package-domain content defined there to the user.

只需更改您的包名称(几乎可以更改任何其他名称),您就可以开始使用了.按照惯例,包名通常是小写的,但您可以将其设为对您的项目有意义的任何名称.有关更多信息,请参阅关于包的教程.

Just change your package name (to virtually anything else), and you'll be good to go. By convention, package names are usually lowercase, but you can make it whatever makes sense for your project. See the tutorial on packages for more.

这篇关于线程“main"中的异常java.lang.SecurityException:禁止的包名:java.lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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