我正在尝试将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)
这是我的导入:
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);
最后一行是构建错误所在的位置。我错过了什么?
答案 0 :(得分:1)
首先,由于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;