请考虑以下代码:
// program is reading data from an excel file, Sheet1 at cell(0,0).
public class Read {
public static void main(String[] args) throws Exception{
File f = new File("sample.xlsx");
FileInputStream fis = new FileInputStream(f);
XSSFWorkbook wb = new XSSFWorkbook(fis); // set a breakpoint here
XSSFSheet sheet = wb.getSheetAt(0);
String data = sheet.getRow(0).getCell(0).getStringCellValue();
System.out.println(data);
wb.close();
}}
程序工作正常,但在创建 XSSFWorkbook 对象时设置断点进行调试时,线程被挂起并且 Eclipse 打开“Reader.class”。
以下是堆栈信息:
Thread [main] (Suspended (exception NullPointerException))
InputStreamReader(Reader).<init>(Object) line: not available
InputStreamReader.<init>(InputStream) line: not available
...
...
XSSFWorkbook.<init>(InputStream) line: 296
Read2.main(String[]) line: 20
请告诉我,这里出了什么问题?
最佳答案
由于发生了 NullPointerException
,Eclipse 挂起线程。看起来您添加了 exception breakpoint在某些时候出现 NullPointerException 。即使在到达您设置的断点之前也会引发此异常。它在其他地方被捕获,这就是为什么你在运行(而不是调试)程序时没有注意到它。
您可以点击“恢复”或在断点 View 中删除异常断点(Alt-Shift-Q,再次 Q 并搜索“断点”)。
关于Java程序工作文件但正在调试 "Thread suspended",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42734814/