在applet $构造函数的对$ psence抛出异常 [英] Presence of constructor in an applet throws exception

查看:173
本文介绍了在applet $构造函数的对$ psence抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行下面的小程序即可。在这里面,那一刻我添加的构造函数(即使是空),该applet抛出一个运行时异常:

  MainFrame.class不能被实例化,java.lang.InstantiationException

如果我删除构造,扔也不例外。我不能有一个构造函数present在applet?

 公开级的大型机扩展JApplet的实现WindowListener的,ActionListener的{
    公共无效的init()
    {
        的System.out.println(小程序步骤1);
        字串[] args = NULL;
        createAndShowGUI(参数);
    }
    私有静态无效createAndShowGUI(字串[] args){/ * code * /}
    公共大型机(最终字串[] args){}
}


解决方案

您需要添加一个默认的构造太...

 公共大型机(){}

I'm running the below applet. In it, the moment I add the constructor (even empty), the applet throws a runtime exception:

MainFrame.class can't be instantiated, java.lang.InstantiationException 

If I remove the constructor, no exception in thrown. Can't I have a constructor present in an applet?

public class MainFrame extends JApplet implements  WindowListener, ActionListener {
    public void init()
    {       
        System.out.println("Applet Step1");
        String[] args = null;
        createAndShowGUI(args);      
    }
    private static void createAndShowGUI(String[] args) { /*code*/ }
    public MainFrame(final String[] args) {}
}

解决方案

You need to add a default constructor too...

public MainFrame() {}

这篇关于在applet $构造函数的对$ psence抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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