NullPointerException 想写一个创建excel的程序,报空指针异常,怎么回事,哪位大神指点一下

public static void main(String[] args) {
ExcelTest3 test3=new ExcelTest3();

String path="E:/1.xls";
test3.creatExcel(path);

}
public void creatExcel(String path)
{
String[] str={"编号","转速","时间","经度","纬度","GPS车速","海拔","GPS方向","GPS里程","判断速度","车速(m/s)","加速度","判断加速度"};
WritableWorkbook wwb = null;
try {
wwb=Workbook.createWorkbook(new File(path));

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if(wwb!=null) {
WritableSheet ws=wwb.createSheet("data",0);
for(int i=0;i<str.length;i++)
{
Label lableC=new Label(0,i,str[i]);
try {
ws.addCell(lableC);
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
wwb.write();
wwb.close();
} catch (IOException | WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}

}

wwb.write和close应该写在for循环外面
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-08
异常信息贴出来,里面会告诉你是哪一行报空了。
相似回答