简体   繁体   English

java.lang.reflect.InvocationTargetException:这是什么原因?

[英]java.lang.reflect.InvocationTargetException : what is the reason for this?

I get the following exception when i try to run the applet : 当我尝试运行applet时出现以下异常:

java.lang.reflect.InvocationTargetException
at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Class sun.plugin2.applet.Plugin2Manager$12 can not access a member of class MyApplet with modifiers ""
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.IllegalAccessException: Class sun.plugin2.applet.Plugin2Manager$12 can not access a member of class MyApplet with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
... 9 more

Exception: java.lang.reflect.InvocationTargetException 例外:java.lang.reflect.InvocationTargetException

Applet Code : 小程序代码:

import javax.swing.*;
import java.awt.*;

class MyApplet extends JApplet {

public JFrame frame;
public JPanel panel;
public JButton button;

public void init() {
    frame = new JFrame();
    panel = new JPanel();
    button = new JButton("click me ");
    panel.setBackground(Color.RED);
    panel.add(button);
    frame.add(panel);
    frame.setSize(300,300);
    frame.setVisible(true);
}   
 }

HTML File : HTML文件:

<applet code="MyApplet" codebase="AppletPackage" archive="JAR.jar" height="800" width="800">

JAR.jar contains a package named AppletPackage that contains the class MyApplet. JAR.jar包含一个名为AppletPackage的包,其中包含MyApplet类。 It also contains the automatically added manifest file. 它还包含自动添加的清单文件。

what is the problem ? 问题是什么 ?

An InvocationTargetException suggests that some reflective call failed. InvocationTargetException表示某些反射调用失败。 It appears that some Sun (Oracle) class is trying to use Reflection to access a class in your code. 看来有些Sun(Oracle)类正在尝试使用Reflection来访问代码中的类。

Your class MyApplet has no public scope modifier. 您的类MyApplet没有public范围修饰符。 If you add it, I expect things will work, as this is what the exception is complaining about. 如果你添加它,我希望事情会有效,因为这是异常的抱怨。

Caused by: java.lang.IllegalAccessException: Class sun.plugin2.applet.Plugin2Manager$12 can not access a member of class MyApplet with modifiers "" 引起:java.lang.IllegalAccessException:类sun.plugin2.applet.Plugin2Manager $ 12 无法使用修饰符“”访问MyApplet类的成员

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

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