我在Android 4.1.2上的某些设备上只有这个例外。所以,我想知道它可能是什么问题。 这是堆栈跟踪 - 我的代码中没有一行,只有来自SDK - 在SDK中发生异常,因此没有错过任何行:
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to
android.widget.LinearLayout$LayoutParams
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:996)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
at android.view.View.measure(View.java:15563)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15563)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5112)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15563)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5112)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15563)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5112)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2423)
at android.view.View.measure(View.java:15563)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2003)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1242)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1417)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1135)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4653)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
在您的代码中,您要导入import android.widget.LinearLayout.LayoutParams
而不是android.view.ViewGroup.LayoutParams;
所以删除import android.widget.LinearLayout.LayoutParams;
并添加import android.view.ViewGroup.LayoutParams;