读取excel文件时出现奇怪的OSGI错误

时间:2014-06-10 05:10:27

标签: java spring osgi apache-poi

我在一个非常简单的Spring项目中遇到错误。这个项目的目标非常简单:它是一个宁静的服务,它连接到一个带有Apache POI的excel文件,并在单元格中读取一些值并返回它,所以当我转到localhost时我可以在Web浏览器中看到它 输出是这样的:Hello world,Excel值是:5

我多次调试代码,我确信这个错误来自"工作表"线

    FileInputStream file = new FileInputStream(new File("file.xlsx"));
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);

    Row row = sheet.getRow(1);
    Cell cell = row.getCell(0);

    value = Integer.toString((int) cell.getNumericCellValue());

以下是错误消息:

initialized with Attributes:{applicationName=BasicService, bundleName=Basic-Serv
ice}
ERROR: Bundle dsp.core [237] EventDispatcher: Error during dispatch. (java.lang.
NullPointerException)
java.lang.NullPointerException
        at com.ge.dsp.core.spi.impl.ServiceManagerServiceImpl.addRegisteredServi
ce(ServiceManagerServiceImpl.java:876)
        at com.ge.dsp.core.spi.impl.ServiceManagerServiceImpl.addRegisteredServi
ce(ServiceManagerServiceImpl.java:856)
        at com.ge.dsp.core.bootloader.impl.CoreServiceListener.serviceChanged(Co
reServiceListener.java:79)
        at org.apache.felix.framework.util.EventDispatcher$4.run(EventDispatcher
.java:925)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.felix.framework.util.EventDispatcher.invokeServiceListener
Callback(EventDispatcher.java:921)
        at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(
EventDispatcher.java:793)
        at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(Even
tDispatcher.java:543)
        at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4260)
        at org.apache.felix.framework.Felix.registerService(Felix.java:3275)
        at org.apache.felix.framework.BundleContextImpl.registerService(BundleCo
ntextImpl.java:346)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl$3.run(Blu
eprintContainerImpl.java:443)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl$3.run(Blu
eprintContainerImpl.java:441)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.registerS
ervice(BlueprintContainerImpl.java:441)
        at org.apache.aries.blueprint.container.ServiceRecipe.register(ServiceRe
cipe.java:190)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.registerS
ervices(BlueprintContainerImpl.java:690)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(Blu
eprintContainerImpl.java:369)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(Bluep
rintContainerImpl.java:261)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47
1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(Execu
torServiceWrapper.java:106)
        at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.r
un(DiscardableRunnable.java:48)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47
1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$201(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(ScheduledThreadPoolExecutor.java:292)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
        at java.lang.Thread.run(Thread.java:744)

0 个答案:

没有答案