小程序中构造函数的存在引发异常 [英] Presence of constructor in an applet throws exception
本文介绍了小程序中构造函数的存在引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行下面的小程序.在其中,当我添加构造函数(甚至为空)时,小程序会抛出运行时异常:
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() {}
这篇关于小程序中构造函数的存在引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文