开发者

How to diagnose in Android (RadioGroup in ScrollView)

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

开发者_如何学Go
    <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?


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.


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:

How to diagnose in Android (RadioGroup in ScrollView)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜