로컬 파일에서 Excel 시트를 가져 와서 일부 계산을 위해 프로그램에 제공된 값을 업로드하는 프로그램을 Java로 작성합니다. 내가 Eclipse 내부에서 컴파일 할 때 모든것이 정상적으로 작동하지만 runnable jar 파일을 만들 때 "Java Exception has Occurred"라는 팝업 오류가 발생합니다. 코드를 살펴 보았습니다. 스프레드 시트에서 값을로드하는 메서드를 제거하면 runnable jar가 올바르게 작동합니다. 하지만 코드를 다시로드하여 값을로드하면 중단됩니다. 전체 프로그램을 중단시키는이 코드 블록에서 어떤 일이 일어나고 있습니까?"Java 예외가 발생했습니다"Apache POI 오류
private static void loadValues() throws IOException{
//FileInputStream file = new FileInputStream(new File("src/PricingData.xls"));
FileInputStream file = new FileInputStream(new File("F:/Sales/Stitt/PricingData.xls"));
HSSFWorkbook wb = new HSSFWorkbook(file);
HSSFSheet sheet = wb.getSheetAt(0);
Cell cell = sheet.getRow(1).getCell(1);
MLPPSF = cell.getNumericCellValue();
cell = sheet.getRow(2).getCell(1);
COPPSF = cell.getNumericCellValue();
cell = sheet.getRow(3).getCell(1);
GPPSF = cell.getNumericCellValue();
cell = sheet.getRow(4).getCell(1);
UPFINISHED = cell.getNumericCellValue();
cell = sheet.getRow(5).getCell(1);
LOWFINISHED = cell.getNumericCellValue();
cell = sheet.getRow(6).getCell(1);
DPPSF = cell.getNumericCellValue();
cell = sheet.getRow(8).getCell(1);
onePanelWaterHeater = cell.getNumericCellValue();
cell = sheet.getRow(9).getCell(1);
twoPanelWaterHeater = cell.getNumericCellValue();
cell = sheet.getRow(10).getCell(1);
saferoomCost = cell.getNumericCellValue();
cell = sheet.getRow(11).getCell(1);
solarPVCost = cell.getNumericCellValue();
cell = sheet.getRow(12).getCell(1);
metlundCost = cell.getNumericCellValue();
cell = sheet.getRow(13).getCell(1);
ervCost = cell.getNumericCellValue();
cell = sheet.getRow(14).getCell(1);
gasFireplaceCost = cell.getNumericCellValue();
cell = sheet.getRow(15).getCell(1);
woodFireplaceCost = cell.getNumericCellValue();
cell = sheet.getRow(18).getCell(1);
allCabVanPercent = cell.getNumericCellValue();
cell = sheet.getRow(19).getCell(1);
allAppliancePercent = cell.getNumericCellValue();
cell = sheet.getRow(20).getCell(1);
allLightFixPercent = cell.getNumericCellValue();
cell = sheet.getRow(21).getCell(1);
allPlumbFixPercent = cell.getNumericCellValue();
cell = sheet.getRow(22).getCell(1);
allFloorCoveringPercent = cell.getNumericCellValue();
cell = sheet.getRow(25).getCell(1);
DepositPercent = cell.getNumericCellValue();
cell = sheet.getRow(26).getCell(1);
Draw1Percent = cell.getNumericCellValue();
cell = sheet.getRow(27).getCell(1);
Draw2Percent = cell.getNumericCellValue();
cell = sheet.getRow(28).getCell(1);
Draw3Percent = cell.getNumericCellValue();
cell = sheet.getRow(29).getCell(1);
Draw4Percent = cell.getNumericCellValue();
cell = sheet.getRow(30).getCell(1);
Draw5Percent = cell.getNumericCellValue();
cell = sheet.getRow(31).getCell(1);
Draw6Percent = cell.getNumericCellValue();
cell = sheet.getRow(32).getCell(1);
Draw7Percent = cell.getNumericCellValue();
cell = sheet.getRow(33).getCell(1);
Draw8Percent = cell.getNumericCellValue();
cell = sheet.getRow(34).getCell(1);
Draw9Percent = cell.getNumericCellValue();
}
그리고 메인은 다음과 같습니다
public static void main(String[] args) {
// TODO Auto-generated method stub
initialize();
try {
loadValues();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
showGUI();
}
편집 : 명령 줄을 통해이를 실행할 때 다음
는 오류입니다.C:\Documents and Settings\Conference Room\SESI>java -jar SESI.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/use
rmodel/Cell
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Cell
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
C:\Documents and Settings\Conference Room\SESI>
나는 예외를 잡는 것이 좋습니다. exception.printStackTrace()가 출력하지 않으면 System.err에 씁니다. 명령 행에서 프로그램을 실행하십시오 (아직 수행하지 않은 경우). 오류를 ^을 콘솔이 있습니다. System.err.println 문을 사용하여 프로그램이 얼마나 멀리 떨어져 있는지 추적하십시오. stacktrace를 강제로 수행 할 수 있다면 가장 잘못되어 가고있는 일을 처리하는 가장 빠르고 쉬운 방법입니다. – arcy
필자는 이것을 게시하고 JAR 파일 내부에서 올바르게 작동하지 않는 "fileinputstream"에 문제가있는 것 같아서 조금 더 연구했습니다. 그러나 나는 아직도 여기에서 어디로 가야할지에 관해서는 조금 잃었다. –
JAR 내에서 작동하지 않는 파일은 주로 항아리 내부에 표시된 디렉토리 트리 내부에 파일을 만들려고 시도하는 것과 관련이 있습니다. "F : \ a \ b \ c"형식을 사용하면 가지고있는 한 작동 할 것입니다 필자가 가정 한 F 드라이브는 해당 디렉토리가있는 Windows 시스템과 디렉토리에 대한 쓰기 액세스 권한이있는 경우입니다. "어디로 가야할까요?"라는 질문에 대한 나의 원래의 견해는 오류가 무엇인지, 그리고 어디서 던져 졌는지에 대한 자세한 정보가 필요하다는 것을 의미합니다. stacktrace는 둘 다 제공합니다. 가서 가져가. – arcy