-14

プロセスの実行中にヒープ領域エラーが発生しました。私のコードを以下に示します。確認して、すぐに解決策を教えてください。

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

5 に答える 5

0

VM 引数で最大ヒープ サイズを増やすことができます。

-Xmx=512M

より明確に理解するには、これを参照してください。

于 2013-07-26T07:07:15.827 に答える
0

opencsv などのいくつかの csv jar を使用することを強くお勧めします。これにより、コードが非常にシンプルになり、読みやすくなります。

コードが長すぎて読めません。コードに無限ループなどの抜け穴がない場合

これを試すことができます。プログラムの実行を開始する前に、Eclipse に -Xms512m -Xmx1024m -XX:MaxPermSize=512m を追加します。

ここで見つけることができる詳細情報: http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

于 2013-07-26T07:10:02.827 に答える
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 つが最善の策になります。

于 2013-07-26T07:11:55.450 に答える