[英]Eclipse stop responding when running a java program
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 (int j = 1; j < row.getLastCellNum();) {
我看不到j
在您的代碼中的任何地方遞增。
主GUI線程上的無限循環會產生凍結IDE的副作用。
正如Shantanu OP 所說 ,添加增量j ++足以解決這種情況:
for(int j=0; j<=row.getLastRowNumber(); j++) {
...
}
您必須在第二個for循環上放置一個遞增或遞減運算符。 您沒有在第二個循環中放置任何條件,這就是為什么您的程序進入無限循環並且Eclipse的性能降低的原因。
使用以下方法更改代碼:
for(int j=0; j<=row.getLastRowNumber(); j++)
{
//Your Code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.