我正在尝试将thquinn's DraggableGridView包含到我的项目中。我遵循那里给出的所有入门指南,包括these steps for adding a jar to my project。 (DraggableGridView.jar显示为引用的库。)

它可以正确编译,但是在运行我的项目时,我在Logcat中收到以下错误:

I/dalvikvm(798): Could not find method com.animoto.android.views.DraggableGridView.addView, referenced from method com.example.GuessWhat.GuessWhat.loadImages
W/dalvikvm(798): VFY: unable to resolve virtual method 11: Lcom/animoto/android/views/DraggableGridView;.addView (Landroid/view/View;)V
D/dalvikvm(798): VFY: replacing opcode 0x6e at 0x003a
E/dalvikvm(798): Could not find class 'com.animoto.android.views.DraggableGridView', referenced from method com.example.GuessWhat.GuessWhat.onCreate
W/dalvikvm(798): VFY: unable to resolve check-cast 15 (Lcom/animoto/android/views/DraggableGridView;) in Lcom/example/GuessWhat/GuessWhat;
D/dalvikvm(798): VFY: replacing opcode 0x1f at 0x0023
D/AndroidRuntime(798): Shutting down VM
W/dalvikvm(798): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
E/AndroidRuntime(798): FATAL EXCEPTION: main
E/AndroidRuntime(798): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GuessWhat/com.example.GuessWhat.GuessWhat}: android.view.InflateException: Binary XML file line #3: Error inflating class com.animoto.android.views.DraggableGridView
E/AndroidRuntime(798):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime(798):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(798):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(798):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(798):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(798):  at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(798):  at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(798):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(798):  at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(798):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

Here's my import:

import com.animoto.android.*;


在我的活动中,我有:

DraggableGridView dgv = ((DraggableGridView) findViewById(R.id.dgv));
ImageView iv = new ImageView(getApplicationContext());
iv.setImageDrawable(new BitmapDrawable(Images[index]));
dgv.addView(iv);


最后一行是构建错误所在的位置。我想念什么?

最佳答案

首先,由于Eclipse可以解决您的依赖关系,而Dalvik无法解决,因此该库似乎未与您的应用程序捆绑在一起。造成这种情况的典型原因是将您的库作为普通的Java依赖项添加到/lib中,而针对Android进行构建时,则需要/libs中的jar。 See also this question.

其次,looking at the source,似乎您的导入未正确指定。 DraggableGridView的限定名称为com.animoto.android.views.DraggableGridView

您的活动应将导入声明为:

import com.animoto.android.views.DraggableGridView;

10-06 13:12