views:

43

answers:

2

I wanted to place a working RadioGroup inside a ScrollView.

This main.xml caused the app to blow up on load... "Sorry! The application... has stopped unexpectedly. Please try again. Force close"

    <ScrollView>
        <RadioGroup android:id="@+id/types">
                    ...

And this worked

    <ScrollView>
        <RadioGroup android:id="@+id/types" android:layout_width="wrap_content" android:layout_height="wrap_content">
            ....

My question, though, is how to figure this out? (aside from trying out random code I find on the Internet). On the force close, the stack trace seems to just be a bunch of launcher stuff, and never mentions my main.xml (using Debug mode in Eclipse with an AVD). Is there an error message somewhere that says that these attributes are missing?

+1  A: 

How to Debug

You should see an error similar to this

java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.

in the logcat system debug output.

Requirements

Width and height are always required. In the Layout Parameters section in the "Declaring Layout" official Dev Guide, it says

All view groups include a width and height (layout_width and layout_height), and each view is required to define them. Many LayoutParams also include optional margins and borders.

Also in the "Layout Resource" Dev Guide, it is stated that all subclasses of View require these two attributes

android:layout_height

Dimension or keyword. Required. The height for the element, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

android:layout_width

Dimension or keyword. Required. The width for the element, as a dimension value (or dimension resource) or a keyword ("fill_parent" or "wrap_content"). See the valid values below.

Brian
Thanks, this is great. Now I know what to read next.
Yar
cool, this goes over how to access logcat in eclipse, and mentions that it's a bit buggy http://www.winksaville.com/blog/programming/debug-logging-in-android/
Yar
+1  A: 

Everything you need is to use Debug mode) When system throws an exception it appears in LogCat and you can find details of issue there. In your case you will get something like that: alt text

FalconSer
Thank you FalconSer, that helps
Yar