未初始化小程序 JAVA
F:\java\java案例开发\lianxi\char1\4>appletviewerElectroAlbum.htmljava.lang.NumberFormatEx...
F:\java\java案例开发\lianxi\char1\4>appletviewer ElectroAlbum.html
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at ElectroAlbum.init(ElectroAlbum.java:29)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
源码:
import java.applet.*;
import java.awt.*;
import java.awt.event.*; //引入相应包
public class ElectroAlbum extends Applet
{
private Choice myChoice; private String[] myString1,myString2; private int totalPics; private Image offI; private Image[] Img; private Graphics offG; private MediaTracker imageTracker; public void init(){ this.setLayout(null); myChoice=new Choice(); myChoice.setBounds(10,10,290,20); totalPics=Integer.parseInt(getParameter("TotalPic")); System.out.println(totalPics); myString1=new String[totalPics]; myString2=new String[totalPics]; Img=new Image[totalPics]; for(int i=0;i<totalPics;i++) { myString1[i]=new String("");
myString2[i]=new String(""); } String s=new String("");
imageTracker=new MediaTracker(this); for(int i=0;i<totalPics;i++) { s=getParameter("Text"+(i+1));
myString1[i]=s; System.out.println(myString1[i]); myChoice.addItem(s); s=getParameter("Picture"+(i+1));
myString2[i]=s; Img[i]=getImage(getDocumentBase(),s);
imageTracker.addImage(Img[i],0);System.out.println(myString2[i]); } try { imageTracker.waitForID(0);} catch(InterruptedException e) { }add(myChoice);offI=createImage(getSize().width,getSize().height-40); offG=offI.getGraphics();
offI=Img[0];offG.drawImage(offI,0,0,this); repaint();} public void paint(Graphics g) {g.drawImage(offI,10,40,this); }
public boolean action(Event e,Object o) {if(e.target==myChoice) { offG.setColor(this.getBackground());
offG.fillRect(0,40,getSize().width,getSize().height-40); offI=Img[myChoice.getSelectedIndex()]; offG.drawImage(offI,0,0,this); repaint(); }return true;
}
} 展开
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at ElectroAlbum.init(ElectroAlbum.java:29)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
源码:
import java.applet.*;
import java.awt.*;
import java.awt.event.*; //引入相应包
public class ElectroAlbum extends Applet
{
private Choice myChoice; private String[] myString1,myString2; private int totalPics; private Image offI; private Image[] Img; private Graphics offG; private MediaTracker imageTracker; public void init(){ this.setLayout(null); myChoice=new Choice(); myChoice.setBounds(10,10,290,20); totalPics=Integer.parseInt(getParameter("TotalPic")); System.out.println(totalPics); myString1=new String[totalPics]; myString2=new String[totalPics]; Img=new Image[totalPics]; for(int i=0;i<totalPics;i++) { myString1[i]=new String("");
myString2[i]=new String(""); } String s=new String("");
imageTracker=new MediaTracker(this); for(int i=0;i<totalPics;i++) { s=getParameter("Text"+(i+1));
myString1[i]=s; System.out.println(myString1[i]); myChoice.addItem(s); s=getParameter("Picture"+(i+1));
myString2[i]=s; Img[i]=getImage(getDocumentBase(),s);
imageTracker.addImage(Img[i],0);System.out.println(myString2[i]); } try { imageTracker.waitForID(0);} catch(InterruptedException e) { }add(myChoice);offI=createImage(getSize().width,getSize().height-40); offG=offI.getGraphics();
offI=Img[0];offG.drawImage(offI,0,0,this); repaint();} public void paint(Graphics g) {g.drawImage(offI,10,40,this); }
public boolean action(Event e,Object o) {if(e.target==myChoice) { offG.setColor(this.getBackground());
offG.fillRect(0,40,getSize().width,getSize().height-40); offI=Img[myChoice.getSelectedIndex()]; offG.drawImage(offI,0,0,this); repaint(); }return true;
}
} 展开
3个回答
展开全部
getParameter("TotalPic")这个方法返回的是html标签的名称,如果你页面上没有TotalPic这个元素的话,那就会报错咯。也可能是其他原因,反正问题根源应该是出在这个上面。你可以自己调试一下。又或者把你的html文件的代码也粘上来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java.lang.NumberFormatException: null
数字格式转换错误 , 你要转为数字的字符串值没有传进来,是空值
数字格式转换错误 , 你要转为数字的字符串值没有传进来,是空值
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
好乱,我见意你还是学一下代码规范!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询