首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android中嵌入Knopflerfish不起作用

在Android中嵌入Knopflerfish不起作用
EN

Stack Overflow用户
提问于 2013-08-03 21:27:56
回答 1查看 478关注 0票数 2

我正在尝试将Knopflerfish框架嵌入到android应用程序中,以便动态加载和卸载包。我遵循了教程

我做的第一步是从链接下载,并将它添加到eclipse项目中的类路径中。

此外,下面是我的onCreate()方法:

代码语言:javascript
复制
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    Map fwprops = new Hashtable(); //CHANGED
    // add any framework properties to fwprops
    FrameworkFactory ff = new FrameworkFactoryImpl();
    mFramework = ff.newFramework(fwprops);
    try {

        mFramework.init(); //ERROR HERE!!

    } catch (BundleException be) {
        // framework initialization failed

        Log.d(TAG, be.getStackTrace().toString());
    }



}

请注意,我更改了代码的一行,因为它显示了语法错误。

即:

代码语言:javascript
复制
Dictionary fwprops = new Hashtable();
to
Map fwprops = new Hashtable(); //CHANGED

句法错误:The method newFramework(Map) in the type FrameworkFactory is not applicable for the arguments (Dictionary)

现在,根据帖子中的@ldx,“我为Knopflerfish提供更好的Android/Dalvik支持而提交的补丁已经被合并,所以修补和重新编译KF不再是必要的了:”

因此,我没有添加任何假设我的代码是足够的,就像现在一样。

当我运行这个应用程序时。我立即得到:屏幕上的Unfortunately, Knopflerfish_Android has stopped

有人能帮忙吗?下面是LogCat:

代码语言:javascript
复制
08-04 18:25:35.233: E/Trace(7018): error opening trace file: No such file or directory (2)
08-04 18:25:36.793: D/AndroidRuntime(7018): Shutting down VM
08-04 18:25:36.793: W/dalvikvm(7018): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-04 18:25:36.813: E/AndroidRuntime(7018): FATAL EXCEPTION: main
08-04 18:25:36.813: E/AndroidRuntime(7018): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.knopflerfish_android/com.example.knopflerfish_android.MainActivity}: java.lang.RuntimeException: Failed to initialize storage org.knopflerfish.framework.bundlestorage.file.BundleStorageImpl
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.os.Looper.loop(Looper.java:137)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at java.lang.reflect.Method.invokeNative(Native Method)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at java.lang.reflect.Method.invoke(Method.java:511)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at dalvik.system.NativeStart.main(Native Method)
08-04 18:25:36.813: E/AndroidRuntime(7018): Caused by: java.lang.RuntimeException: Failed to initialize storage org.knopflerfish.framework.bundlestorage.file.BundleStorageImpl
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.FrameworkContext.init(FrameworkContext.java:343)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.SystemBundle.doInit(SystemBundle.java:513)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.SystemBundle.init(SystemBundle.java:125)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at com.example.knopflerfish_android.MainActivity.onCreate(MainActivity.java:39)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.Activity.performCreate(Activity.java:5104)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-04 18:25:36.813: E/AndroidRuntime(7018):     ... 11 more
08-04 18:25:36.813: E/AndroidRuntime(7018): Caused by: java.lang.reflect.InvocationTargetException
08-04 18:25:36.813: E/AndroidRuntime(7018):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.FrameworkContext.init(FrameworkContext.java:341)
08-04 18:25:36.813: E/AndroidRuntime(7018):     ... 17 more
08-04 18:25:36.813: E/AndroidRuntime(7018): Caused by: java.lang.RuntimeException: Cannot create directory: /fwdir/bs
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.Util.getFileStorage(Util.java:99)
08-04 18:25:36.813: E/AndroidRuntime(7018):     at org.knopflerfish.framework.bundlestorage.file.BundleStorageImpl.<init>(BundleStorageImpl.java:127)
08-04 18:25:36.813: E/AndroidRuntime(7018):     ... 20 more
08-04 18:25:39.543: I/Process(7018): Sending signal. PID: 7018 SIG: 9
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-06 07:35:42

在注释// add any framework properties to fwprops中,我只需添加框架启动属性,指定框架使用的持久存储目录。因为它是Android,所以存储目录的默认值似乎不起作用。相反,我应该指定sdcard下的目录。因此,我增加了这一行:

代码语言:javascript
复制
 fwprops.put("org.osgi.framework.storage", "sdcard/fwdir");

下面是我更新的代码:

代码语言:javascript
复制
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Map<String, String> fwprops = new Hashtable<String, String>(); //CHANGED

        // add any framework properties to fwprops
        fwprops.put("org.osgi.framework.storage", "sdcard/fwdir");

        FrameworkFactory ff = new FrameworkFactoryImpl();
        mFramework = ff.newFramework(fwprops);

        try {

            mFramework.init(); //THIS WORKS NOW :P :P

        } catch (BundleException be) {
            // framework initialization failed

            Log.d(TAG, be.getStackTrace().toString());

        }

    }  

多亏了这两个链接:存储 http://www.knopflerfish.org/releases/current/docs/bundledoc/index.html?docpage=framework/index.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18037496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档