Programmatically creating scrollview(s) from custom component in android
- by jaapbeetstra
I'm trying to build a compound control in Android, containing (among other things) a ScrollView. Things go wrong when I try to view the control in Eclipse, crashing with a NullPointerException after the error message: "Parser is not a BridgeXmlBlockParser".
Stacktrace:
java.lang.NullPointerException
at android.view.View.<init>(View.java:1720)
at android.view.ViewGroup.<init>(ViewGroup.java:277)
at android.widget.FrameLayout.<init>(FrameLayout.java:83)
at android.widget.ScrollView.<init>(ScrollView.java:128)
at android.widget.ScrollView.<init>(ScrollView.java:124)
at android.widget.ScrollView.<init>(ScrollView.java:120)
at my.compound.control.StringPicker.onMeasure(StringPicker.java:46)
...
I've traced the error to the following conditions:
The NPE is thrown because a Context.obtainStyledAttributes() call returns null when the attrs argument passed is null.
This only applies to the BridgeContext implementation used in Eclipse, which expects attrs to be an instance of the BridgeXmlBlockParser.
The attrs argument is null because I create the ScrollView using the (Context) constructor.
There is a workaround of course, which is passing the attrs I receive when Eclipse constructs the compound control, but I don't want all the attributes set on the compound control to apply to my inner control.
Am I doing something wrong, is this a bug in Android Eclipse, ...?