线程“main"中的异常java.lang.SecurityException:禁止的包名:java.lang

编程入门 行业动态 更新时间:2024-10-18 05:58:27
本文介绍了线程“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.URLClassLoader.defineClass(Unknown Source) at java.URLClassLoader.access$100(Unknown Source) at java.URLClassLoader$1.run(Unknown Source) at java.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.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

本文发布于:2023-11-27 04:07:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636522.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   异常   main   SecurityException   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!