我正在开展一项相当复杂的活动,包括片段和自定义视图。活动本身有一个布局文件,包含一个带有其他子视图的LinearLayout。最近,我在FrameLayout中添加了两个子视图,因为我需要它们相互叠加,而不是在垂直序列中相互跟随。结果我开始收到以下错误。我理解并预料到可能的错误,但问题是跟踪没有将错误锚定在我的项目中。我不知道我的代码中的哪个位置可以确定错误。假设我的活动名称是DogActivity,通常应该有一些行com.company.app.DogActivity.java (45)
。但不是在这种情况下。我在下面提供了跟踪。有谁知道我如何配置eclipse以显示导致异常的实际代码中的行?
03-27 22:37:59.181: E/AndroidRuntime(408): FATAL EXCEPTION: main
03-27 22:37:59.181: E/AndroidRuntime(408): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.LinearLayout.measureVertical(LinearLayout.java:683)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.LinearLayout.onMeasure(LinearLayout.java:602)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.View.measure(View.java:15293)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.View.measure(View.java:15293)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1418)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.LinearLayout.measureVertical(LinearLayout.java:709)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.LinearLayout.onMeasure(LinearLayout.java:602)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.View.measure(View.java:15293)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 22:37:59.181: E/AndroidRuntime(408): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2425)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.View.measure(View.java:15293)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1876)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1112)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1301)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1010)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4255)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.Choreographer.doFrame(Choreographer.java:525)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.os.Handler.handleCallback(Handler.java:615)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.os.Handler.dispatchMessage(Handler.java:92)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.os.Looper.loop(Looper.java:137)
03-27 22:37:59.181: E/AndroidRuntime(408): at android.app.ActivityThread.main(ActivityThread.java:4849)
03-27 22:37:59.181: E/AndroidRuntime(408): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 22:37:59.181: E/AndroidRuntime(408): at java.lang.reflect.Method.invoke(Method.java:511)
03-27 22:37:59.181: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-27 22:37:59.181: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-27 22:37:59.181: E/AndroidRuntime(408): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您正在为views使用不同的参数。在发生异常的地方不会说确切的行号。检查所有错误放置Layout.Parameter的视图。
例如假设你使用的是RelativeLayout,但是你将参数设置为LinearLayout params。或者如果你使用表格布局和 参数为RelativeLayou.PayoutParams。