没取到属性文件里的默认值,所以在做Integer.parseInt时对null进行转化

解决方案 »

  1.   

    代码如下:
    /**************html*******************/
    <html>
    <body bgColor="000000">
    <table width="500" align="center">
    <tr><td>
        <APPLET CODE="testApplet.class" WIDTH="300"
            HEIGHT="300"></APPLET>
    </td></tr>
    </table>
    </applet>
    </body>
    </html>
    /*****************java*********************/
    import java.applet.*;
    import java.awt.*;
    import java.awt.image.*;//Applet的5个功能描述
    public class testApplet extends Applet
    {
        private Image Img;           //图像对象
        private int intFontSize;     //文字大小    public void init()           //初始化
        {
            String strImgFile = getParameter("img");
            Img = getImage(getCodeBase(),strImgFile);        String strFontSize = getParameter("fontSize");
            intFontSize = Integer.parseInt(strFontSize);
            
            log("小程序初始化完毕");
        }//init()    public void start()          //程序运行
        {
           log("小程序运行.....");
        }//start()
      
        public void stop()           //程序停止
        {
            log("小程序停止.....");
        }//stop()
     
        public void destory()         //程序销毁
        {
            log("小程序销毁.....");
        }//destory()    public void paint(Graphics g)            // 绘制操作
        { 
           log("绘图....");
           g.drawImage(Img,0,0,getSize().width,getSize().height,this);
           log("设置绘图颜色....");
           g.setColor(Color.black);
           log("创建字体对象....");
           Font f = new Font("Monospaced",Font.BOLD,intFontSize);
           log("设置绘图字体....");
           g.setFont(f);
           log("写字....");
           g.drawString("这是一个测试",30,150);
        }//paint()    public void log(String strInfo)
        {
            System.out.println(strInfo);
        }//log()
    }/** testApplet */
            
       
      

  2.   

    你读进来的值是数字吗?怀疑。。,不是数字的话,或者是null值,肯定会报错的
      

  3.   

    你在html里面根本没有
       <param   name="fontSize"  value="....">这样的字段,而你在程序里面取的是个null
      

  4.   

    Integer.parseInt(strFontSize)对strFontSize的转化有错
    可能为null或者为不能转化为Integer的值
      

  5.   

    首先可以确定你的Applet是没有问题的,问题在于你的html文件有问题。先看看我改过后的html文件:
    <html>
    <body bgColor="000000">
    <table width="500" align="center">
    <tr><td>
    <APPLET CODE="testApplet.class" WIDTH="300" HEIGHT="300">
    <param name="fontSize" value="24">
    <param name="img" value="./testimg.jpg">
    </APPLET>
    </td></tr>
    </table>
    </body>
    </html>你的html文件没有提供param,所以会出现错误提示。另外你贴的代码多了个</applet>。testimg.jpg放在当前目录。这样运行就没有问题了。