NoClassDefFoundError的使用objenesis在Android上,当 [英] NoClassDefFoundError when using objenesis on Android

查看:602
本文介绍了NoClassDefFoundError的使用objenesis在Android上,当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用Android应用程序的 com.rits.cloning org.objenesis。* 库深克隆对象。
的目的是相同的对象添加到我的树结构类两次或更多次,而无需担心原始对象所引用到同一个对象。
由于普通的的clone()只是浅拷贝对象,我用的是提到的库。

I'm developing an android app which use the com.rits.cloning and org.objenesis.* libs to deep clone object. The purpose is to add same object to my tree structure class twice or more without worrying that the original object is referencing to the same object. Since the regular clone() just shallow copy the object, I use the mentioned libs.

在开发Android项目,我创建了一个Java项目来实现我的树,它使用这些库工作得很好。
然后我把它导入到Android项目(并添加 com.rits.cloning org.objenesis。* 作为外部lib目录,然后检查这两个库中的 Java构建路径>订单与出口)。
但是,当我运行它,就在那里我所说的行 deepClone(),这个错误在LogCat中出现并应用程序是强制关闭:

Before develop the android project, I created a java project to implement my tree and it worked fine using those libs. Then I imported it to the android project (and also add com.rits.cloning, org.objenesis.* as external lib and then check both libs in the Java Build Path > Order and Export). But when I run it, right at the line where I call deepClone(), this error showed up in the LogCat and the app is force closed:

E/AndroidRuntime(280): FATAL EXCEPTION: main
E/AndroidRuntime(280): java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory
E/AndroidRuntime(280):  at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflectionFactoryInstantiator.java:40)
E/AndroidRuntime(280):  at org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:85)
E/AndroidRuntime(280):  at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:90)
E/AndroidRuntime(280):  at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
E/AndroidRuntime(280):  at com.rits.cloning.Cloner.newInstance(Cloner.java:291)
E/AndroidRuntime(280):  at com.rits.cloning.Cloner.cloneInternal(Cloner.java:468)
E/AndroidRuntime(280):  at com.rits.cloning.Cloner.deepClone(Cloner.java:327)
E/AndroidRuntime(280):  at com.susterblonde.project_monitoring.project.WBS.add(WBS.java:35)
E/AndroidRuntime(280):  at com.susterblonde.project_monitoring.project.ProjectUtility.demoPlan(ProjectUtility.java:101)
E/AndroidRuntime(280):  at com.susterblonde.project_monitoring.ProjectSelection.onCreate(ProjectSelection.java:45)
E/AndroidRuntime(280):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(280):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(280):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(280):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(280):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(280):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(280):  at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(280):  at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(280):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(280):  at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(280):  at dalvik.system.NativeStart.main(Native Method)

我一派,并已分别尝试了这一点:

I googled and have tried this separately:


  • 清洁项目

  • 删除 com.rits.cloning org.objenesis。* 从构建路径,并重新进行添加

  • 重新排列这些库,使他们在右下方Android的依赖

  • 重新排列这些库,使他们对所有库的顶部

  • clean the project
  • remove com.rits.cloning and org.objenesis.* from the build path and readd
  • reorder those libs so that they on right below the Android Dependencies
  • reorder those libs so that they on top of all libs

我不认为这是因为Eclipse更新,因为我更新了它这个星期发生之前。

I don't think it's because of eclipse update because I updated it weeks before this happen.

下面是源$ C ​​$ C:

Here's the source code:

package com.susterblonde.tree;

import java.util.ArrayList;
import com.rits.cloning.Cloner;

public class MyTree {
    Data o;
    MyTree parent;
    ArrayList<MyTree> child = new ArrayList<MyTree>();

    public void add(MyTree tree) {
        Cloner c = new Cloner();

        MyTree temp =   c.deepClone(tree); //this is where the app crashed
        temp.parent = this;
        child.add(temp);
    }

    public static void main(String[] args) {
        MyTree tree1 = new MyTree();
        MyTree tree2 = new MyTree();

        tree1.add(tree2);
        tree1.add(tree2);
        tree1.add(tree2);
        //The result wanted here is tree1 has 3 different but identical child objects
        //NOT 3 child which refer to the same one object
    }
}

class Data {
    double value;
}

问:


  • 为什么我得到的错误,我该如何摆脱它?

  • 有没有执行我的树中的任何其他方式?

原谅我的英语水平。

感谢您:)

推荐答案

在Eclipse中,当你在Java中添加外部库构建路径对话框中,不要忘了也切换到排序和导出选项卡,勾选该库的名字在列表中。这是必须的,从而该库在运行时发现,不仅在编译时

In Eclipse when you add an external library in the Java Build Path dialog, don't forget to also switch to the Order and Export tab and tick that library's name in the list. This is needed so that the library is found at run-time, not only at compile time.

<一个href=\"http://stackoverflow.com/questions/9847443/noclassdeffounderror-when-running-instrumentation-test-with-ant/9958669#9958669\">NoClassDefFoundError运行与蚂蚁仪表测试时,

这篇关于NoClassDefFoundError的使用objenesis在Android上,当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆