我用java编写了一个程序,它从本地文件中获取一个excel表并将给定的值上传到程序中进行一些计算。当我在 Eclipse 中编译时,一切都按预期工作,但是当我创建一个可运行的 jar 文件时,我收到一个弹出错误“发生 Java 异常”。我浏览了代码,如果我删除了从电子表格中加载值的方法,那么可运行的 jar 就可以正常工作。但是如果我把代码放回去加载值,它就会中断。这段代码中发生了什么导致整个程序崩溃?
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>