2013-07-26 59 views
-11

我在運行進程時出現了堆空間錯誤。我的代碼如下。請驗證它,並儘快給我解決方案。超出存儲空間異常

public static void Read_File(String Filename) 
     throws IOException { 
    FileInputStream myInput = null; 

    myInput = new FileInputStream(Filename); 
    POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput); 
    HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem); 
    HSSFSheet mySheet = myWorkBook.getSheetAt(0); 

    int RowCount = 0; 
    for (Row row : mySheet) { 
     if (RowCount >= 1) { 
      Cell Eincell = row.getCell(0); 
      Cell Namecell = row.getCell(1); 
      Cell InCareofNamecell = row.getCell(2); 
      Cell Addresscell = row.getCell(3); 
      Cell Citycell = row.getCell(4); 
      Cell Statecell = row.getCell(5); 
      Cell ZipCodecell = row.getCell(6); 
      Cell GroupExemptionNumbercell = row.getCell(7); 
      Cell SubsectionCodecell = row.getCell(8); 
      Cell AffiliationCodecell = row.getCell(9); 
      Cell ClassificationCodecell = row.getCell(10); 
      Cell RulingDatecell = row.getCell(11); 
      Cell DeductibilityCodecell = row.getCell(12); 
      Cell FoundationCodcell = row.getCell(13); 
      Cell ActivityCodecell = row.getCell(14); 
      Cell OrganizationCodecell = row.getCell(15); 
      Cell ExemptOrganizationStatusCodecell = row.getCell(16); 
      Cell AdvancedRulingExpirationDatecell = row.getCell(17); 
      Cell TaxPeriodcell = row.getCell(18); 
      Cell AssetCodecell = row.getCell(19); 
      Cell IncomeCodecell = row.getCell(20); 
      Cell FilingRequirementCodecell = row.getCell(21); 
      Cell PFFilingRequirementCodecell = row.getCell(22); 
      Cell Blankcell = row.getCell(23); 
      Cell AccountingPeriodcell = row.getCell(24); 
      Cell AssetAmountcell = row.getCell(25); 
      Cell IncomeAmountcell = row.getCell(26); 
      Cell NegativeSigncell = row.getCell(27); 
      Cell Form90RevenueAmountcell = row.getCell(28); 
      Cell NegativeSign1cell = row.getCell(29); 
      Cell NTEECodecell = row.getCell(30); 
      Cell SortorSecondaryNamecell = row.getCell(31); 

      if (Eincell == null) { 
       Einvalue = 0; 
      } else { 
       try { 
        String ass = String.valueOf(Eincell.getStringCellValue()); 
        Einvalue = Integer.parseInt(ass); 
       } catch (Exception ex) { 
        Einvalue = 0; 
       } 
      } 

      if (Namecell == null) { 
       namevalue = "0"; 
      } else { 
       try { 
        namevalue = Namecell.getStringCellValue(); 
       } catch (Exception ex1) { 
        namevalue = "0"; 
       } 
      } 

      if (InCareofNamecell == null) { 
       incarevalue = "0"; 
      } else { 
       try { 
        incarevalue = InCareofNamecell.getStringCellValue(); 
       } catch (Exception ex1) { 
        incarevalue = "0"; 
       } 
      } 
      if (Addresscell == null) { 
       addressvalue = "0"; 
      } else { 
       try { 
        addressvalue = Addresscell.getStringCellValue(); 
       } catch (Exception ex1) { 
        addressvalue = "0"; 
       } 
      } 
      if (Citycell == null) { 
       cityvalue = "0"; 
      } else { 
       try { 
        cityvalue = Citycell.getStringCellValue(); 
       } catch (Exception ex1) { 
        cityvalue = "0"; 
       } 
      } 
      if (Statecell == null) { 
       Statevalue = "0"; 
      } else { 
       try { 
        Statevalue = Statecell.getStringCellValue(); 
       } catch (Exception ex1) { 
        Statevalue = "0"; 
       } 
      } 

      if (ZipCodecell == null) { 
       zipvalue = "0"; 
      } else { 
       try { 
        zipvalue = ZipCodecell.getStringCellValue(); 
       } catch (Exception ex1) { 
        zipvalue = "0"; 
       } 
      } 
      if (GroupExemptionNumbercell == null) { 
       groupvalue = 0; 
      } else { 
       try { 
        groupvalue = (int) GroupExemptionNumbercell.getNumericCellValue(); 
       } catch (Exception ex) { 
        groupvalue = 0; 
       } 
      } 

      if (SubsectionCodecell == null) { 
       SubsectionCodevalue = 0; 
      } else { 
       try { 
        SubsectionCodevalue = (int) SubsectionCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        SubsectionCodevalue = 0; 
       } 
      } 
      if (AffiliationCodecell == null) { 
       AffiliationCodevalue = 0; 
      } else { 
       try { 
        AffiliationCodevalue = (int) AffiliationCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        AffiliationCodevalue = 0; 
       } 
      } 
      if (ClassificationCodecell == null) { 
       ClassificationCodevalue = 0; 
      } else { 
       try { 
        ClassificationCodevalue = (int) ClassificationCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        ClassificationCodevalue = 0; 
       } 
      } 
      if (RulingDatecell == null) { 
       RulingDatevalue = 0; 
      } else { 
       try { 
        RulingDatevalue = (int) RulingDatecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        RulingDatevalue = 0; 
       } 
      } 

      if (DeductibilityCodecell == null) { 
       DeductibilityCodevalue = 0; 
      } else { 
       try { 
        DeductibilityCodevalue = (int) DeductibilityCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        DeductibilityCodevalue = 0; 
       } 
      } 
      if (FoundationCodcell == null) { 
       Foundationcodevalue = 0; 
      } else { 
       try { 
        Foundationcodevalue = (int) FoundationCodcell.getNumericCellValue(); 
       } catch (Exception ex) { 
        Foundationcodevalue = 0; 
       } 
      } 

      if (ActivityCodecell == null) { 
       ActivityCodevalue = 0; 
      } else { 
       try { 
        ActivityCodevalue = (int) ActivityCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        ActivityCodevalue = 0; 
       } 
      } 
      if (OrganizationCodecell == null) { 
       OrganizationCodevalue = 0; 
      } else { 
       try { 
        OrganizationCodevalue = (int) OrganizationCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        OrganizationCodevalue = 0; 
       } 
      } 

      if (ExemptOrganizationStatusCodecell == null) { 
       ExemptOrganizationStatusCodevalue = 0; 
      } else { 
       try { 
        ExemptOrganizationStatusCodevalue = (int) ExemptOrganizationStatusCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        ExemptOrganizationStatusCodevalue = 0; 
       } 
      } 
      if (AdvancedRulingExpirationDatecell == null) { 
       AdvancedRulingExpirationDatevalue = 0; 
      } else { 
       try { 
        AdvancedRulingExpirationDatevalue = (int) AdvancedRulingExpirationDatecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        AdvancedRulingExpirationDatevalue = 0; 
       } 
      } 
      if (TaxPeriodcell == null) { 
       TaxPeriodvalue = 0; 
      } else { 
       try { 
        TaxPeriodvalue = (int) TaxPeriodcell.getNumericCellValue(); 
       } catch (Exception ex) { 
        TaxPeriodvalue = 0; 
       } 
      } 

      if (AssetCodecell == null) { 
       AssetCodevalue = 0; 
      } else { 
       try { 
        AssetCodevalue = (int) AssetCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        AssetCodevalue = 0; 
       } 
      } 
      if (IncomeCodecell == null) { 
       IncomeCodevalue = 0; 
      } else { 
       try { 
        IncomeCodevalue = (int) IncomeCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        IncomeCodevalue = 0; 
       } 
      } 

      if (FilingRequirementCodecell == null) { 
       FilingRequirementCode = 0; 
      } else { 
       try { 
        FilingRequirementCode = (int) FilingRequirementCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        FilingRequirementCode = 0; 
       } 
      } 

      if (PFFilingRequirementCodecell == null) { 
       PFFilingRequirementCodevalue = 0; 
      } else { 
       try { 
        PFFilingRequirementCodevalue = (int) PFFilingRequirementCodecell.getNumericCellValue(); 
       } catch (Exception ex) { 
        PFFilingRequirementCodevalue = 0; 
       } 
      } 
      try { 
       Blankvalue = Blankcell.getStringCellValue(); 
      } catch (Exception ex) { 
       Blankvalue = "0"; 
      } 
      try { 
       AccountingPeriodvalue = (int) AccountingPeriodcell.getNumericCellValue(); 
      } catch (Exception ex) { 
       AccountingPeriodvalue = 0; 
      } 
      try { 
       AssetAmountvalue = AssetAmountcell.getNumericCellValue(); 
      } catch (Exception ex) { 
       AssetAmountvalue = 0.0D; 
      } 
      try { 
       IncomeAmountvalue = IncomeAmountcell.getNumericCellValue(); 
      } catch (Exception ex) { 
       IncomeAmountvalue = 0.0D; 
      } 
      try { 
       navigaresign = NegativeSigncell.getStringCellValue(); 
      } catch (Exception ex) { 
       navigaresign = "0"; 
      } 
      try { 
       Form990RevenueAmountvalue = Form90RevenueAmountcell.getNumericCellValue(); 
      } catch (Exception ex) { 
       Form990RevenueAmountvalue = 0.0D; 
      } 
      try { 
       navigaresign1_value = NegativeSign1cell.getStringCellValue(); 
      } catch (Exception ex) { 
       navigaresign1_value = "0"; 
      } 

      try { 
       NTEE_Code_value = NTEECodecell.getStringCellValue(); 
      } catch (Exception ex) { 
       NTEE_Code_value = "0"; 
      } 
      try { 
       SortorSecondaryName_value = SortorSecondaryNamecell.getStringCellValue(); 
      } catch (Exception ex) { 
       SortorSecondaryName_value = "0"; 
      } 
      try { 
       YearValue = String.valueOf(TaxPeriodvalue).substring(0, 4).trim(); 
      } catch (Exception ex) { 
       YearValue = "0"; 
      } 
      try { 
       RangeValue = Math.ceil(Form990RevenueAmountvalue); 
      } catch (Exception ex) { 
       RangeValue = 0.0D; 
      } 

      if (RangeValue < 1000000.0D) { 
       ResultRange = "Less than $1 Million"; 
      } else if ((RangeValue > 1000000.0D) && (RangeValue < 9999999.0D)) { 
       ResultRange = " $1-9.99 Million"; 
      } else if ((RangeValue > 10000000.0D) && (RangeValue < 24999999.0D)) { 
       ResultRange = " $10-24.99 Million"; 
      } else if ((RangeValue > 25000000.0D) && (RangeValue < 49999999.0D)) { 
       ResultRange = " $25-49.99 Million"; 
      } else if ((RangeValue > 50000000.0D) && (RangeValue < 74999999.0D)) { 
       ResultRange = " $50-74.99 Million"; 
      } else if ((RangeValue > 100000000.0D) && (RangeValue < 124999999.0D)) { 
       ResultRange = " $100-124.99 Million"; 
      } else if ((RangeValue > 125000000.0D) && (RangeValue < 149999999.0D)) { 
       ResultRange = " $125-149.99 Million"; 
      } else if ((RangeValue > 150000000.0D) && (RangeValue < 199999999.0D)) { 
       ResultRange = " $150-199.99 Million"; 
      } else if ((RangeValue > 200000000.0D) && (RangeValue < 249999999.0D)) { 
       ResultRange = " $200-249.99 Million"; 
      } else if ((RangeValue > 250000000.0D) && (RangeValue < 299999999.0D)) { 
       ResultRange = " $250-299.99 Million"; 
      } else if ((RangeValue > 300000000.0D) && (RangeValue < 349999999.0D)) { 
       ResultRange = " $300-349.99 Million"; 
      } else if ((RangeValue > 350000000.0D) && (RangeValue < 399999999.0D)) { 
       ResultRange = " $350-399.99 Million"; 
      } else if ((RangeValue > 400000000.0D) && (RangeValue < 449999999.0D)) { 
       ResultRange = " $400-449.99 Million"; 
      } else if ((RangeValue > 450000000.0D) && (RangeValue < 499999999.0D)) { 
       ResultRange = " $450-499.99 Million"; 
      } else if ((RangeValue > 500000000.0D) && (RangeValue < 549999999.0D)) { 
       ResultRange = " $500-549.99 Million"; 
      } else if ((RangeValue > 550000000.0D) && (RangeValue < 599999999.0D)) { 
       ResultRange = " $550-599.99 Million"; 
      } else if ((RangeValue > 600000000.0D) && (RangeValue < 649999999.0D)) { 
       ResultRange = "$600-649.99 Million"; 
      } else if ((RangeValue > 650000000.0D) && (RangeValue < 699999999.0D)) { 
       ResultRange = " $650-699.99 Million"; 
      } else if ((RangeValue > 700000000.0D) && (RangeValue < 749999999.0D)) { 
       ResultRange = "$700-749.99 Million"; 
      } else if ((RangeValue > 750000000.0D) && (RangeValue < 799999999.0D)) { 
       ResultRange = "$750-799.99 Million"; 
      } else if ((RangeValue > 800000000.0D) && (RangeValue < 899999999.0D)) { 
       ResultRange = "$800-899.99 Million"; 
      } else if ((RangeValue > 900000000.0D) && (RangeValue < 999999999.0D)) { 
       ResultRange = "$900-999.99"; 
      } else if ((RangeValue > 1000000000.0D) && (RangeValue < 4999999999.0D)) { 
       ResultRange = "$1-4.99 Billion"; 
      } else if ((RangeValue > 5000000000.0D) && (RangeValue < 14999999999.0D)) { 
       ResultRange = "$5-14.99 Billion"; 
      } else if ((RangeValue > 15000000000.0D) && (RangeValue < 24999999999.0D)) { 
       ResultRange = "$15-24.99 Billion"; 
      } else if ((RangeValue > 25000000000.0D) && (RangeValue < 49999999999.0D)) { 
       ResultRange = "$25-49.99 Billion"; 
      } else if ((RangeValue > 50000000000.0D) && (RangeValue < 74999999999.0D)) { 
       ResultRange = "$50-74.99 Billion"; 
      } else if ((RangeValue > 75000000000.0D) && (RangeValue < 99999999999.0D)) { 
       ResultRange = "$75-99.99 Billion"; 
      } else if ((RangeValue > 100000000000.0D) && (RangeValue < 149999999999.0D)) { 
       ResultRange = "$100-149.99 Billion"; 
      } else if ((RangeValue > 150000000000.0D) && (RangeValue < 199999999999.0D)) { 
       ResultRange = "$150-199.99 Billion"; 
      } else if ((RangeValue > 200000000000.0D) && (RangeValue < 249999999999.0D)) { 
       ResultRange = "$200-249.99 Billion"; 
      } else if ((RangeValue > 250000000000.0D) && (RangeValue < 299999999999.0D)) { 
       ResultRange = " $250-299.99 Billion"; 
      } else if ((RangeValue > 300000000000.0D) && (RangeValue < 349999999999.0D)) { 
       ResultRange = " $300-349.99 Billion"; 
      } else if ((RangeValue > 350000000000.0D) && (RangeValue < 399999999999.0D)) { 
       ResultRange = " $350-399.99 Billion"; 
      } else if ((RangeValue > 400000000000.0D) && (RangeValue < 449999999999.0D)) { 
       ResultRange = " $400-449.99 Billion"; 
      } else if ((RangeValue > 450000000000.0D) && (RangeValue < 499999999999.0D)) { 
       ResultRange = " $450-499.99 Billion"; 
      } else if (RangeValue > 500000000000.0D) { 
       ResultRange = " $500 Billion +"; 
      } 

      table.addRow(new Object[]{Integer.valueOf(Einvalue), namevalue, incarevalue, addressvalue, cityvalue, Statevalue, zipvalue, Integer.valueOf(groupvalue), Integer.valueOf(SubsectionCodevalue), Integer.valueOf(AffiliationCodevalue), Integer.valueOf(ClassificationCodevalue), Integer.valueOf(RulingDatevalue), Integer.valueOf(DeductibilityCodevalue), Integer.valueOf(Foundationcodevalue), Integer.valueOf(ActivityCodevalue), Integer.valueOf(OrganizationCodevalue), Integer.valueOf(ExemptOrganizationStatusCodevalue), Integer.valueOf(AdvancedRulingExpirationDatevalue), Integer.valueOf(TaxPeriodvalue), Integer.valueOf(AssetCodevalue), Integer.valueOf(IncomeCodevalue), Integer.valueOf(FilingRequirementCode), Integer.valueOf(PFFilingRequirementCodevalue), Blankvalue, Integer.valueOf(AccountingPeriodvalue), Double.valueOf(AssetAmountvalue), Double.valueOf(IncomeAmountvalue), navigaresign, Double.valueOf(Form990RevenueAmountvalue), navigaresign1_value, NTEE_Code_value, SortorSecondaryName_value, YearValue, ResultRange}); 
     } 

     System.gc(); 

     RowCount++; 
    } 

    System.gc(); 
    myInput.close(); 
} 
+1

您嘗試使用更多的堆大小? –

+16

我不認爲是獲得幫助的好方法「請確認並儘快給我解決方案。」 – Fedy2

+0

您是使用給定API創建電子表格的人嗎? –

回答

0

您可以增加虛擬機參數中的最大堆大小。

-Xmx = 512M

爲了更清楚地理解,你可以參考this

0

我強烈建議你使用一些csv jar如opencsv等,它會使代碼變得簡單易讀。

我無法理解您的代碼,因爲它太長時間無法閱讀。如果代碼沒有漏洞,如無限循環等

你可以試試這個。 添加-Xms512m -Xmx1024m -XX:MaxPermSize參數=512米在日食開始前,運行程序

更多信息,你可以在這裏找到:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

0

添加用System.out進行處理的每一行,所以你可以看到進度。您還可以添加:

if(RowCount%10==0){ 
    System.out.println(RowCount); 
} 
if(RowCount > 100){ 
    return; 
} 
//tweak numbers per your needs/expectations 

並查看它是否適用於第一組行。如果你的代碼永遠不會通過第1行,那麼你知道你只是有另一個錯誤。如果您的電子表格中只有20行,並且您看到第100行,那麼您知道它不會停止在您認爲的結尾處。

如果您有一個龐大的電子表格(例如100,000行),並且在死前快樂地達到60,000行左右,那麼關於增加堆空間的其他答案之一將是您最好的選擇。

1

如果您使用Eclipse,here是有關如何增加堆空間的完整教程。

轉到eclipse文件夾

查找Eclipse的圖標在eclipse文件夾

右鍵點擊它,你會得到選項「顯示包內容」

目錄文件夾將在屏幕上打開

如果你在Mac上,那麼你會發現「MacOS」

Open MacOS fol明鏡,你會發現eclipse.ini文件

打開它在Word或編輯

任何文件編輯器...

-XX:MaxPermSize參數=256米

-Xms40m

-Xmx512m ...

更換-Xmx512m至-Xmx1024m

保存文件並重新啓動您的Eclipse