Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically creating scrollview(s) from custom component in android
    primarykey
    data
    text
    <p>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".</p> <p>Stacktrace:</p> <pre><code>java.lang.NullPointerException at android.view.View.&lt;init&gt;(View.java:1720) at android.view.ViewGroup.&lt;init&gt;(ViewGroup.java:277) at android.widget.FrameLayout.&lt;init&gt;(FrameLayout.java:83) at android.widget.ScrollView.&lt;init&gt;(ScrollView.java:128) at android.widget.ScrollView.&lt;init&gt;(ScrollView.java:124) at android.widget.ScrollView.&lt;init&gt;(ScrollView.java:120) at my.compound.control.StringPicker.onMeasure(StringPicker.java:46) ... </code></pre> <p>I've traced the error to the following conditions:</p> <ul> <li>The NPE is thrown because a <code>Context.obtainStyledAttributes()</code> call returns <code>null</code> when the <code>attrs</code> argument passed is <code>null</code>.</li> <li>This only applies to the <code>BridgeContext</code> implementation used in Eclipse, which expects <code>attrs</code> to be an instance of the <code>BridgeXmlBlockParser</code>.</li> <li>The <code>attrs</code> argument is <code>null</code> because I create the ScrollView using the (Context) constructor.</li> </ul> <p>There is a workaround of course, which is passing the <code>attrs</code> 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.</p> <p>Am I doing something wrong, is this a bug in Android Eclipse, ...?</p> <p>This is what my.compound.control.StringPicker.onMeasure looks like (stripped it a bit for clarity):</p> <pre><code>@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (this.getChildCount() != requestedLength) { this.removeAllViews(); int childWidth = getWidth() / requestedLength; int childHeight = getHeight(); for (int i = 0; i &lt; requestedLength; i++) { ScrollView child = new ScrollView(getContext()); // NPE here child.setLayoutParams(new LayoutParams(childWidth, childHeight)); addView(child); } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload