简体   繁体   中英

Java program working file but on debugging “Thread suspended”

Please consider the following code:

// 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();
}}

Program is working fine , but on debugging with break-point set at creating XSSFWorkbook object, thread is suspended and Eclipse opens "Reader.class".

Following is the stack information:

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

Please tell, what's wrong here?

Eclipse suspends the thread because a NullPointerException has occurred. It looks like you added an exception breakpoint for NullPointerException at some point. This exception is thrown even before you hit the breakpoint that you set. It is caught somewhere else, that is why you don't notice it when you run (not debug) the program.

You can either just hit "Resume" or remove the exception breakpoint in the breakpoints view (Alt-Shift-Q, Q again and search for "breakpoints").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM