0

I have this Exception only on some devices on android 4.1.2. So, I want to know what is the problem it can be. Here is stack trace - no one line from my code, only from SDK - exception happens in SDK, so no lines were missed:

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)
6
  • 1
    change import android.widget.LinearLayout.LayoutParams; to import android.widget.ViewGroup.LayoutParams; Commented Oct 28, 2014 at 6:58
  • Please show some code Commented Oct 28, 2014 at 6:58
  • 1
    It seems that the params you dynamically set for the view does not match the params type the parent expects Commented Oct 28, 2014 at 6:59
  • Your import statement for LayoutParams might be importing ViewGroup.LayoutParams or vice versa ...Please check it once Commented Oct 28, 2014 at 7:02
  • error in imports, import view with actionbar. Commented Oct 28, 2014 at 7:07

1 Answer 1

1

In your code you are importing import android.widget.LinearLayout.LayoutParams instead of android.view.ViewGroup.LayoutParams;

so Delete import android.widget.LinearLayout.LayoutParams;

and Add import android.view.ViewGroup.LayoutParams;

Sign up to request clarification or add additional context in comments.

1 Comment

I think you are right, I tried to change my code in this way, but can not check because of I don't have device on android 4.1.2. So, I just accept your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.