Eclipse在运行java程序时停止响应 package com.selenium; 导入java.io.FileInputStream; 导入org.apache.poi.ss.usermodel.*; 导入org.apache.poi.ss.usermodel.WorkbookFactory; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebElement; 导入org.openqa.selenium.firefox.FirefoxDriver; 导入java.io.IOException; 公共类EXCEL{ 公共静态void main(字符串[]args)引发异常,NullPointerException{ //WebDriver=newfirefoxdriver(); //网络元素wb; 字符串值; 试一试{ FileInputStream文件=新的FileInputStream(“C:\\Documents and Settings\\OMEGA\\Desktop\\Test Planning and Documents\\Automation Data.xlsx”); 工作簿数据=WorkbookFactory.create(文件); Sheet Sheet=data.getSheet(“Sheet1”); 对于(int i=1;i

Eclipse在运行java程序时停止响应 package com.selenium; 导入java.io.FileInputStream; 导入org.apache.poi.ss.usermodel.*; 导入org.apache.poi.ss.usermodel.WorkbookFactory; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebElement; 导入org.openqa.selenium.firefox.FirefoxDriver; 导入java.io.IOException; 公共类EXCEL{ 公共静态void main(字符串[]args)引发异常,NullPointerException{ //WebDriver=newfirefoxdriver(); //网络元素wb; 字符串值; 试一试{ FileInputStream文件=新的FileInputStream(“C:\\Documents and Settings\\OMEGA\\Desktop\\Test Planning and Documents\\Automation Data.xlsx”); 工作簿数据=WorkbookFactory.create(文件); Sheet Sheet=data.getSheet(“Sheet1”); 对于(int i=1;i,java,eclipse,Java,Eclipse,,循环可能永远不会结束: package com.selenium; import java.io.FileInputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openq

,循环可能永远不会结束:

package com.selenium;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.IOException;

public class Exxcel {
public static void main(String[] args) throws Exception,NullPointerException{
    //WebDriver driver= new FirefoxDriver();
    //WebElement wb;
    String Value;
    try{
    FileInputStream file= new FileInputStream("C:\\Documents and Settings\\OMEGA\\Desktop\\Test Planning And Documents\\Automation Data.xlsx");
    Workbook data=WorkbookFactory.create(file);
    Sheet sheet=data.getSheet("Sheet1");
    for(int i=1;i<=sheet.getLastRowNum();i++){
        Row row = sheet.getRow(i);
        if(row != null){
        // Putting condition to check row is null or not
            for (int j = 1; j < row.getLastCellNum();) {
            if (row.getCell(j) != null) {
                // Putting condition to check row cell is null or not
                String value=row.getCell(j).getStringCellValue();
                Value=value;
                //String value1=row.getCell(j+1).getStringCellValue();
                String[] array= new String[2];
                array[0]=Value;
                //array[1]=value1;
                if( array[0] != null  ) {
                    // Putting condition to check array[] is null or not
                    System.out.println(array[0]); 
                    //System.out.println(array[1]);
                 }   
                }
            }  
        }
      } 
    }catch(NullPointerException n){
        n.printStackTrace();
        //System.out.println("Null");
        }// catch
    }//main
}//class

您必须在第二个for循环上放置一个递增或递减运算符。您没有在第二个for循环中放置任何条件,这就是为什么您的程序在无限循环中运行,并且eclipse的性能变慢的原因

使用以下命令更改代码:

for(int j=0; j<=row.getLastRowNumber(); j++) {
  ...
}

for(int j=0;jany记录显示程序仍在运行的提示?调试您的代码以使您的生活更轻松。感谢您的快速回复。在调试时,我没有检查第二个for循环条件,是的,因为程序将进入无限循环。代码是否更改并添加了增量(j++)现在一切正常。这和我的回答和OP的结论有什么不同吗?(两天前都做了)
for(int j=0; j<=row.getLastRowNumber(); j++) {
  ...
}
for(int j=0; j<=row.getLastRowNumber(); j++)
{
  //Your Code
}