0

下面的堆栈跟踪对我来说似乎没用......有人知道如何找出导致崩溃的原因吗?

09-20 13:40:11.136: D/AndroidRuntime(8819): Shutting down VM
09-20 13:40:11.136: W/dalvikvm(8819): threadid=1: thread exiting with uncaught exception (group=0x410b82a0)
09-20 13:40:11.146: E/AndroidRuntime(8819): FATAL EXCEPTION: main
09-20 13:40:11.146: E/AndroidRuntime(8819): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.ListView.setupChild(ListView.java:1809)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.ListView.makeAndAddView(ListView.java:1778)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.ListView.fillDown(ListView.java:678)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.ListView.fillFromTop(ListView.java:739)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.ListView.layoutChildren(ListView.java:1628)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.AbsListView.onLayout(AbsListView.java:2303)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.View.layout(View.java:14063)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewGroup.layout(ViewGroup.java:4655)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2017)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1838)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.Choreographer.doFrame(Choreographer.java:525)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.os.Handler.handleCallback(Handler.java:615)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.os.Looper.loop(Looper.java:137)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at android.app.ActivityThread.main(ActivityThread.java:4898)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at java.lang.reflect.Method.invokeNative(Native Method)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at java.lang.reflect.Method.invoke(Method.java:511)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-20 13:40:11.146: E/AndroidRuntime(8819):     at dalvik.system.NativeStart.main(Native Method)

有没有一种技术可以用来解决这个问题?

4

3 回答 3

3

这不是没用的。它告诉您您正在创建RelativeLayout.LayoutParams某处的实例并在您应该使用AbsListView.LayoutParams. 当您以LayoutParams编程方式设置时,通常会发生这种情况。

于 2013-09-20T20:50:25.020 回答
1

使用 LayoutParams,它总是会发生。每个版本都有各种不同的版本,您需要确保导入的版本适合您尝试使用的版本。

当您应该导入 android.widget.AbsListView.LayoutParams 时,您正在导入 android.widget.RelativeLayout.LayoutParams。或相反亦然。

于 2013-09-20T20:51:55.587 回答
1

AndroidLayoutParam为其视图使用多个具有类似命名约定的类。这里要注意的关键是它们都是它们所针对的布局的静态嵌套类,并且扩展了基ViewGroup.LayoutParams类。

例如,您有:

  • AbsListView.LayoutParams extends ViewGroup.LayoutParams
  • ViewPager.LayoutParams extends ViewGroup.LayoutParams
  • LinearLayout.LayoutParams extends ViewGroup.MarginLayoutParams extends ViewGroup.LayoutParams

等等。您遇到的问题是您使用错误LayoutParams,这就是为什么它给您一个ClassCastException. 确保您为正在使用的布局使用了适当的 LayoutParams。

在您的情况下,您正在使用RelativeLayout.LayoutParams而不是AbsListView.LayoutParams.

于 2013-09-20T21:02:28.100 回答