帮我看看空指针异常?????????????????????????

xiaofengpangpang 2006-06-12 11:02:03
public class testt extends JApplet{
JButton butt=null;
JPanel p=null;
public void init()
{
String host=this.getCodeBase().getHost();
this.getContentPane().add(new JLabel(host));
this.setSize(500,500);
this.setContentPane(getPane());
}
private JPanel getPane()
{
p=new JPanel();
butt=new JButton();
URL urlIcon=getClass().getResource("/images/zoomin.JPG");
Icon butticon=new ImageIcon(urlIcon);//出现空指针的地方
butt.setIcon(butticon);
p.add(butt);
return p;
}
}
urlIcon是空的,也就是getClass().getResource("/images/zoomin.JPG");没返回URL的值,帮我看看错在哪里了?(路径是正确的)
...全文
327 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaofengpangpang 2006-06-13
  • 打赏
  • 举报
回复
解决了,
crazycy 2006-06-13
  • 打赏
  • 举报
回复
谢谢哈 我解决了没有?
xiaoxiaoyuying 2006-06-13
  • 打赏
  • 举报
回复
恭喜了
trumplet 2006-06-13
  • 打赏
  • 举报
回复
ImageIcon icon = new ImageIcon(getImage(getDocumentBase(),"images//icon.gif"));
mq612 2006-06-12
  • 打赏
  • 举报
回复
ImageIcon icon = new ImageIcon(getImage(getDocumentBase(),"images/icon.gif"));
ll42002 2006-06-12
  • 打赏
  • 举报
回复
路径问题,解决办法见二楼。
zyg158 2006-06-12
  • 打赏
  • 举报
回复
是路径问题,呵呵~~~~
UnAgain 2006-06-12
  • 打赏
  • 举报
回复
mark

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧