更新嵌入到Android应用程序中的Felix中的捆绑包显示:“java.io.FileNotFoundException”

时间:2013-09-02 09:35:00

标签: android osgi bundle apache-felix osgi-bundle

我将Apache Felix嵌入到Android应用程序中。启动和停止捆绑工作正常。但我想通过阅读另一个捆绑文件来更新捆绑包。这是我的代码:

bundle1 = bundleContext1.installBundle("file:sdcard/Download/AndroidImageViewer_1.0.0.201308221559.jar");
            bundle1.start();
            bundle1.stop();
            try {
                bundle1.update(new FileInputStream(new File("file:sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar")));
            } catch (FileNotFoundException e) {e.printStackTrace();}
            bundle1.start();

我希望这可行,并且我的包会更新,但不幸的是,我收到以下错误:

    java.io.FileNotFoundException: /file:sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar (No such file or directory)
    at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:239)

此异常发生在以下行:

bundle1.update(new FileInputStream(new File("file:sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar")));

我完全相信捆绑包AndroidVideoPlayer_1.0.0.201308231205.jar存在于下载指南中,我之前尝试启动它并且工作正常。我很迷惑。有帮助吗?感谢。

1 个答案:

答案 0 :(得分:1)

啊,你正在从URL创建一个File对象!

 new File("file:sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar"))

试试这个

 File file = new File( "sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar" );
 context.update( new FileInputStream(file));

 context.update( new URL("file:sdcard/Download/AndroidVideoPlayer_1.0.0.201308231205.jar").openStream());