20

I use a view which has RelativeLayout -> ScrollView -> LinearLayout. I get exception:

11-22 11:17:24.605: ERROR/AndroidRuntime(5161): FATAL EXCEPTION: main
11-22 11:17:24.605: ERROR/AndroidRuntime(5161): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3131)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.view.View.measure(View.java:8172)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.view.ViewRoot.performTraversals(ViewRoot.java:805)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.os.Looper.loop(Looper.java:144)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at android.app.ActivityThread.main(ActivityThread.java:4937)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at java.lang.reflect.Method.invokeNative(Native Method)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at java.lang.reflect.Method.invoke(Method.java:521)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-22 11:17:24.605: ERROR/AndroidRuntime(5161):     at dalvik.system.NativeStart.main(Native Method)

Why does it happen only occassionally? Why is there no detail of where the code failed?

Update: I suspect it should fail around this code:

EditText input = new EditText(context);
input.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

LayoutParams is RelativeLayout.LayoutParams

6
  • 1
    please post the code of your adapter Commented Nov 22, 2011 at 12:22
  • 3
    Well, show us xml and java code. How do you expect us to solve this without them? Commented Nov 22, 2011 at 12:23
  • 1
    we don't care what you do suspect :) give us a larger portion of your code Commented Nov 22, 2011 at 12:33
  • added snippet for the code that I believe is causing trouble. Commented Nov 22, 2011 at 12:33
  • 1
    see, the point is that if you think that the problem is there you would probably be smart enough to fix that on your own. But the problem might have roots way before in your code. At least, post the whole method where that snippet is. Since you can't fix the problem on your own where you think you found it, it'll be probably elsewhere. Commented Nov 22, 2011 at 12:39

1 Answer 1

45

Use new LinearLayout.LayoutParams(...) instead of new LayoutParams(...)

You always need to use the parent layout's class for the LayoutParams. E.g. if EditText is inside FrameLayout then FrameLayout.LayoutParams must be used.

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

1 Comment

Relative > scrollView > LinearLayout > EditText

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.