站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v6.0, Java 2 SDK 英文文档

java.lang.InstantiationException: Either "code" or "object" ... - JDK 5 Documentation v6.0, Java 2 SDK 英文文档

java.lang.InstantiationException: Either "code" or "object" should be specified, but not both.


Symptoms

When running an applet in a browser using the Sun JRE, an InstantiationException is thrown. The same applet runs under the Microsoft  VM.

Cause

There are two possible causes.

  1. Both code and object attributes are specified in the <APPLET> tag:

    <APPLET code=MyApplet object=MyApplet.ser width=100 height=100>
    </APPLET>

    The Sun JRE can access either the code or the object attribute, but not both.
     
  2. A code attribute is specified in the <APPLET> tag, and an object attribute is specified in a <PARAM> tag :

    <APPLET code=MyApplet width=100 height=100>
    <PARAM name="object" value="someValue">
    </APPLET>

    public class MyApplet extends java.applet.Applet
    {
            public void init()
            {
                   String value = getParameter("object");
            }
            ....
    }

    The Sun JRE does not support object as a parameter name.

Resolution

        The workaround in the first case is to eliminate the code attribute in the <APPLET> tag:

             <APPLET object=MyApplet.ser width=100 height=100>
             </APPLET>

        The workaround in the second case is to change the parameter name to a different name:

             <APPLET code=MyApplet width=100 height=100>
             <PARAM name="property1" value="someValue">
             </APPLET>

             public class MyApplet extends java.applet.Applet
             {
                 public void init()
                 {
                         String value = getParameter("property1");
                 }
                 ....
             }

Related Information

        N/A