Java中Exception in thread "AWT-EventQueue-0" ,在线等答案,请高手赐教!
我的代码如下:importjava.io.File;importjava.io.IOException;importjxl.Cell;importjxl.Sheet;im...
我的代码如下:
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadXLS
{
private Workbook workbook = null;
private Sheet sheet =null;
private Cell cell = null;
private String ulr;
private String con;
private String tatol;
private String[][] str;
public ReadXLS(String ulr)
{
this.ulr=ulr;
}
public String[][] readXls()
{
try
{
workbook=Workbook.getWorkbook(new File(ulr));
}
catch (BiffException e)
{
try {
throw new Exception("file to import not found!");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
catch (IOException e)
{
e.printStackTrace();
}
sheet= workbook.getSheet(0);
int columnCount=sheet.getColumns();
int rowCount=sheet.getRows();
for (int i = 0; i <rowCount; i++)
{
for (int j = 0; j <columnCount; j++)
{
cell=sheet.getCell(j, i);
con=cell.getContents();
tatol+=con;
str[i][j] =cell.getContents();
}
}
workbook.close();
return str;
}
}
请高手们解答一下,为什么会抛以下异常,谢谢!
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at cha.ReadXLS.readXls(ReadXLS.java:87)
at form.StartMain$4.actionPerformed(StartMain.java:183)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
str[i][j] =cell.getContents();
这行代码有问题,请各位高手指点下!!!急!!!!!! 展开
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadXLS
{
private Workbook workbook = null;
private Sheet sheet =null;
private Cell cell = null;
private String ulr;
private String con;
private String tatol;
private String[][] str;
public ReadXLS(String ulr)
{
this.ulr=ulr;
}
public String[][] readXls()
{
try
{
workbook=Workbook.getWorkbook(new File(ulr));
}
catch (BiffException e)
{
try {
throw new Exception("file to import not found!");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
catch (IOException e)
{
e.printStackTrace();
}
sheet= workbook.getSheet(0);
int columnCount=sheet.getColumns();
int rowCount=sheet.getRows();
for (int i = 0; i <rowCount; i++)
{
for (int j = 0; j <columnCount; j++)
{
cell=sheet.getCell(j, i);
con=cell.getContents();
tatol+=con;
str[i][j] =cell.getContents();
}
}
workbook.close();
return str;
}
}
请高手们解答一下,为什么会抛以下异常,谢谢!
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at cha.ReadXLS.readXls(ReadXLS.java:87)
at form.StartMain$4.actionPerformed(StartMain.java:183)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
str[i][j] =cell.getContents();
这行代码有问题,请各位高手指点下!!!急!!!!!! 展开
4个回答
展开全部
贴出来的代码不全
无法回答
按照异常信息理解,应该是:
at cha.ReadXLS.readXls(ReadXLS.java:87)
ReadXLS.java 文件中的 87 行出现了空对象类型错误,好好检查一下程序逻辑,可能有些极端情况没有考虑到而出现了对象未初始化就使用的情况!
无法回答
按照异常信息理解,应该是:
at cha.ReadXLS.readXls(ReadXLS.java:87)
ReadXLS.java 文件中的 87 行出现了空对象类型错误,好好检查一下程序逻辑,可能有些极端情况没有考虑到而出现了对象未初始化就使用的情况!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
AWT-EventQueue 这个线程好像是获取windows事件并把它载入到java awt 事件队列的线程。具体问题我看不出来。可以往这方面想想。希望对你有帮助。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
str[i][j] =cell.getContents();
这一行有问题的,你在仔细看看吧......
这一行有问题的,你在仔细看看吧......
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
抛出NullPointerException
异常呀
异常呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
更多回答(2)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询