1

I'm getting a few exception reports coming in from my app caused by the RuntimeException thrown from a custom UI component class I'm using. Here is the code (credit for this code goes to this post):

public class WrapingSlidingDrawer extends SlidingDrawer {

public WrapingSlidingDrawer(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);

    int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
    mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
    mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}

public WrapingSlidingDrawer(Context context, AttributeSet attrs)
{
    super(context, attrs);

    int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
    mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
    mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{

    int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);

    int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);

    if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED)
    {
        throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
    }

and here is the declaritive XML I'm using:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/customDrawerLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true">

    <com.package.WrapingSlidingDrawer
        android:id="@+id/slidingDrawer"
        android:handle="@+id/Handle"
        android:content="@+id/contentLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

Both the custom sliding drawer and parent both specify layout width and height attributes. Therefore, any ideas on what could cause UNSPECIFIED to show up? Its happening very rarely.

Community
  • 1
  • 1
Chris Knight
  • 24,333
  • 24
  • 88
  • 134
  • Have you managed to determine whether it's always the `widthSpecMode` or the `heightSpecMode` (or both) which seems to come back as UNSPECIFIED? – tomato Nov 10 '11 at 00:35
  • Afraid not as its a rare case and I can't reproduce it, though perhaps its a good idea to log which it is. – Chris Knight Nov 10 '11 at 09:43

0 Answers0