Skip to content Skip to sidebar Skip to footer

Classcastexception Linearlayout Layoutparams

I got an Actionbar and some Fragments. The Problem is my Homescreen. There is an overview Fragment on the left side and a detail Fragment on the right side. My TabListener is Dynam

Solution 1:

What's going on is that a view's LayoutParams are actually the type of the parent. In this case you're getting a FrameLayout$LayoutParams because your LinearLayout is inside a FrameLayout.

Why is it the type of the parent? That's because they store information that's useful for the parent to lay them out. If you were to retrieve the layout parameters for the EditText or ListView you would get LinearLayout$LayoutParams.

Solution 2:

Exception clearly states that you are trying to cast FrameLayout to LinearLayout. This occurs in onViewCreated() method in ListSearchFragment.java file, line 184. So replace this:

LayoutParamslp= (LayoutParams) myView.getLayoutParams();

with this:

LinearLayout.LayoutParamslp= 
                  (LinearLayout.LayoutParams) myView.getLayoutParams();

Before you do that, you can hover your mouse pointer on LayoutParams in your current code and see in bubble that it is in fact android.widget.RelativeLayout.LayoutParams hence your exception. See:

enter image description here

Solution 3:

There is another reason (or bug) for this exception:

If the view's ID is also being used in another layout, then it'll try to cast LayoutParams for the Parent views used in both layouts.

Answer : Dont use same id in different layouts :)

Post a Comment for "Classcastexception Linearlayout Layoutparams"