简体   繁体   English

将类添加到Swing包中-结果是可见函数上的IllegalAccessError

[英]Adding a class to the Swing package — result is an IllegalAccessError on a visible function

I am creating a new Widget using the same structure/style as the other Swing widgets. 我正在使用与其他Swing小部件相同的结构/样式创建一个新的小部件。 To this end I have put my UI class in javax.swing.plaf.basic. 为此,我将UI类放在javax.swing.plaf.basic中。 As part of my UI implementation I am using the javax.swing.plaf.basic.LazyActionMap class. 作为我的UI实施的一部分,我正在使用javax.swing.plaf.basic.LazyActionMap类。 Eclipse is considering it to be visible as it has the same package name, however at runtime I get a java.lang.IllegalAccessError exception (presumably it is not visible at runtime). Eclipse认为它是可见的,因为它具有相同的程序包名称,但是在运行时我遇到了java.lang.IllegalAccessError异常(大概在运行时不可见)。

It seem that even though I have given my class the same package name, and Eclipse is considering them to be in the same package, at runtime they are not. 看起来,即使我给我的类指定了相同的程序包名称,并且Eclipse也在考虑将它们放在同一程序包中,但在运行时却不是。

Is there something I am doing incorrectly? 我做错了什么吗? The reason I am trying to have visibility to internal library classes is because for the prototype of the widget I am re-using the JSlider UI code. 我试图对内部库类具有可见性的原因是,对于小部件的原型,我正在重用JSlider UI代码。 In the future I will transition to drawing the slider from scratch. 将来,我将过渡到从头开始绘制滑块。

Classes loaded through a different class loader are considered to belong to different packages. 通过其他类加载器加载的类被视为属于不同的包。 At compile time your compiler will not know how you are going to deploy, so can't see the mistake. 在编译时,编译器不会知道您将如何部署,因此看不到错误。 You could add the code as system classes with -Xbootclasspath/a: , but that's very naughty and you shouldn't do it. 您可以使用-Xbootclasspath/a:将代码添加为系统类,但这很顽皮,您不应该这样做。

You should put your own classes in your own packages, well outside of javax . 您应该将自己的类放在您自己的包中,并且位于javax之外。 java.* classes wont even get loaded by non-bootstrap class loaders. 非引导类加载器甚至不会加载java.*类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM