14

I have implemented the new style Collapsible Toolbar. I am using the same code as the example (Cheesesquare) demo app - which of course works fine on all devices. I need help figuring out what I am doing different then the sample (so my app won't crash).

My app runs great on 5.0+ devices, but crashes on older devices (OS 4.4.4) with an error that I can't isolate to my code (no references to my project's classes in the stack). Seems so strange to me that this is device specific (if this was a code error, it would crash everywhere)

I have (tried, but didn't help):

  • looked through all my XML and Java to ensure I am not setting a 0 as any dimension on any view
  • Ensured I am not setting padding anywhere
  • Removed ALL margins (just to check - didn't help, added back)
  • Removed all my setBackground() methods (no help)
  • Removed all elevation and radius attributes
  • Setting ALL CardViews to Visibility.GONE (still crashes even with all CardViews no being drawn)

The crash is coming from a class in AOSP: https://android.googlesource.com/platform/frameworks/support/+/master/v7/cardview/eclair-mr1/android/support/v7/widget/RoundRectDrawableWithShadow.java

I see a related Bug opened (but not assigned): https://code.google.com/p/android/issues/detail?id=157919 Interestingly, this bug states this doesn't crash on 4.3, but I don't have that device handy.

Suggestions about how I can debug the cause of this crash?:

E/AndroidRuntime(  708): java.lang.IllegalArgumentException: radius must be > 0
E/AndroidRuntime(  708):    at android.graphics.RadialGradient.<init>(RadialGradient.java:53)
E/AndroidRuntime(  708):    at android.support.v7.widget.RoundRectDrawableWithShadow.buildShadowCorners(RoundRectDrawableWithShadow.java:285)
E/AndroidRuntime(  708):    at android.support.v7.widget.RoundRectDrawableWithShadow.buildComponents(RoundRectDrawableWithShadow.java:307)
E/AndroidRuntime(  708):    at android.support.v7.widget.RoundRectDrawableWithShadow.draw(RoundRectDrawableWithShadow.java:209)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15493)
E/AndroidRuntime(  708):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15511)
E/AndroidRuntime(  708):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime(  708):    at android.support.v4.widget.NestedScrollView.draw(NestedScrollView.java:1679)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1040)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15511)
E/AndroidRuntime(  708):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14397)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15222)
E/AndroidRuntime(  708):    at android.view.ViewGroup.drawChild(ViewGroup.java:3340)
E/AndroidRuntime(  708):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3176)
E/AndroidRuntime(  708):    at android.view.View.draw(View.java:15511)
E/AndroidRuntime(  708):    at android.widget.FrameLayout.draw(FrameLayout.java:472)
E/AndroidRuntime(  708):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2623)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14402)
E/AndroidRuntime(  708):    at android.view.View.getDisplayList(View.java:14444)
E/AndroidRuntime(  708):    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1597)
E/AndroidRuntime(  708):    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1469)
E/AndroidRuntime(  708):    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)
E/AndroidRuntime(  708):    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2666)
E/AndroidRuntime(  708):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2234)
E/AndroidRuntime(  708):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1267)
E/AndroidRuntime(  708):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6638)
E/AndroidRuntime(  708):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
E/AndroidRuntime(  708):    at android.view.Choreogra

My activity:

public class PaymentActivity extends AppCompatActivity {
    public static final String XTRA_DEVICENAME = "";
    private static String deviceName;
    private ItemDto deviceDto;
    private Activity mActivity;

    private OkHttpClient okclient;

    //Views
    private RelativeLayout infoLayout;
    private TextView deviceOwner;
    private TextView devicePrice;
    private TextView deviceInfo;
    private TextView payDurationTitle;
    private TextView payPriceTitle;
    private TextView payDurationText;
    private TextView payPriceText;
    private Button upBtn;
    private Button downBtn;
    private TextView incText;
    private View incrDivider;
    private FloatingActionButton fab;
    private ProgressBar devInfoProgress;
    private LinearLayout incrBtnView;

    private int mIterVal = 1;

    private Constants.ColorInfo colorTheme = Constants.ColorInfo.GREY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this;

        Intent intent = getIntent();
        deviceName = intent.getStringExtra(XTRA_DEVICENAME);

        setTheme(ColorUtil.getThemeForDevice(deviceName));
        colorTheme = ColorUtil.getColorTheme(deviceName);
        setContentView(R.layout.act_payment);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        okclient = new OkHttpClient();

        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(deviceName.toUpperCase());

        okclient = new OkHttpClient();

        final ImageView imageView = (ImageView) findViewById(R.id.backdrop);
        // todo get better default image
        final String paymentIconUrl = "http://xxx/" + deviceName + "_lg.png";

        Glide.with(mActivity)
                .load(paymentIconUrl)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.ic_logo_allwhite)
                .error(R.drawable.ic_logo_allwhite)
                .into(imageView);

        setupViews();
        new GetItemInfoTask().execute(deviceName);
    }

    private void setupViews() {
        infoLayout = (RelativeLayout) findViewById(R.id.device_info_layout);
        infoLayout.setBackgroundColor(getResources().getColor(ColorUtil.getDeviceColor(deviceName, ColorUtil.COLOR_SECONDARY)));

        incrBtnView = (LinearLayout) findViewById(R.id.incr_btn_view);
        deviceOwner = (TextView) findViewById(R.id.info_owner);
        devicePrice = (TextView) findViewById(R.id.info_price);
        deviceInfo = (TextView) findViewById(R.id.info_max_amount);
        payDurationTitle = (TextView) findViewById(R.id.paidDurationTitle);
        payPriceTitle = (TextView) findViewById(R.id.paidAmountTitle);
        payDurationText = (TextView) findViewById(R.id.paidDurationText);
        payPriceText = (TextView) findViewById(R.id.paidAmountText);

        devInfoProgress = (ProgressBar) findViewById(R.id.devinfo_progress);
        devInfoProgress.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.card_white), android.graphics.PorterDuff.Mode.MULTIPLY);

        Drawable tmpDrawable = ColorUtil.getTintedDrawable(mActivity, R.drawable.ic_attach_money, colorTheme.getSecondary());
        payPriceTitle.setCompoundDrawablesWithIntrinsicBounds(tmpDrawable, null, null, null);

        Drawable tmpDrawable2 = ColorUtil.getTintedDrawable(mActivity, R.drawable.ic_clock, colorTheme.getSecondary());
        payDurationTitle.setCompoundDrawablesWithIntrinsicBounds(tmpDrawable2, null, null, null);

        upBtn = (Button) findViewById(R.id.pay_inc_up_btn);
        downBtn = (Button) findViewById(R.id.pay_inc_down_btn);
        incText = (TextView) findViewById(R.id.pay_inc_text);
        incrDivider = (View) findViewById(R.id.iter_divider);

        upBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ...
            }
        });
        downBtn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                ...
            }
        });

        upBtn.setBackground(mActivity.getResources().getDrawable(colorTheme.getSelectorId()));
        downBtn.setBackground(mActivity.getResources().getDrawable(colorTheme.getSelectorId()));

        fab = (FloatingActionButton) findViewById((R.id.pay_fab_btn));
        //TODO - manually coloring FAB, should do with color state list
        fab.setEnabled(false);
        fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.grey_300)));

        fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.card_white)));
                ...

            }
        });

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_payment, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    private class GetItemInfoTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            ...

            return null;
        }

        @Override
        protected void onPostExecute(String result) {
        ...

        }

        @Override
        protected void onPreExecute() {
            devInfoProgress.setVisibility(View.VISIBLE);
        }

        @Override
        protected void onProgressUpdate(Void... values) {

        }
    }

}

My Layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/payments_backdrop_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:transitionName="device_img"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/grey_200"
            android:orientation="vertical">

            <RelativeLayout
                android:id="@+id/device_info_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/info_owner"
                    style="@style/DeviceInfo" />

                <TextView
                    android:id="@+id/info_price"
                    style="@style/DeviceInfo"
                    android:layout_below="@+id/info_owner"/>

                <TextView
                    android:id="@+id/info_max_amount"
                    style="@style/DeviceInfo"
                    android:layout_below="@+id/info_price"
                    android:layout_marginBottom="@dimen/grid1" />

                <ProgressBar
                    android:id="@+id/devinfo_progress"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_width="@dimen/rythm48"
                    android:layout_height="@dimen/rythm48"
                    android:layout_toRightOf="@+id/info_price"
                    android:layout_marginRight="@dimen/grid5"
                    android:layout_marginTop="@dimen/grid1"
                    android:visibility="gone" />

           </RelativeLayout>

            <android.support.v7.widget.CardView
                android:id="@+id/device_info_card"
                style="@style/CardView"
                card_view:cardCornerRadius="4dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/launch_title"
                        style="@style/CardTitle"
                        android:text="Current Amounts" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/confirm_text"
                        android:layout_marginBottom="@dimen/grid5"
                        android:orientation="horizontal"
                        android:weightSum="2">

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/paidAmountTitle"
                                style="@style/TextAppearance.AppCompat.Medium"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:drawableLeft="@drawable/ic_dollar"
                                android:gravity="center"
                                android:text="@string/paid_amount_title" />

                            <TextView
                                android:id="@+id/paidAmountText"
                                style="@style/TextAppearance.AppCompat.Headline"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/paidDurationTitle"
                                style="@style/TextAppearance.AppCompat.Medium"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:drawableLeft="@drawable/ic_clock"
                                android:gravity="center"
                                android:text="@string/paid_duration_title" />

                            <TextView
                                android:id="@+id/paidDurationText"
                                style="@style/TextAppearance.AppCompat.Headline"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />

                        </LinearLayout>
                    </LinearLayout>

                    <View
                        android:id="@+id/iter_divider"
                        android:layout_width="wrap_content"
                        android:layout_height="1dp"
                        android:layout_marginBottom="@dimen/grid2"
                        android:layout_marginTop="@dimen/grid_5"
                        android:background="@color/grey_400"
                        android:visibility="gone"/>

                    <LinearLayout
                        android:id="@+id/incr_btn_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/grid5"
                        android:layout_marginLeft="@dimen/grid4"
                        android:layout_marginRight="@dimen/grid4"
                        android:orientation="horizontal"
                        android:gravity="center"
                        android:weightSum="3"
                        android:visibility="gone">

                        <Button
                            android:id="@+id/pay_inc_down_btn"
                            style="@style/InfoButton"
                            android:layout_width="@dimen/rythm48"
                            android:layout_height="@dimen/rythm48"
                            android:text="-"
                            android:textSize="32sp"
                            android:layout_weight="1"/>

                        <TextView
                            android:id="@+id/pay_inc_text"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="1"
                            android:gravity="center"
                            android:layout_marginRight="@dimen/grid2"
                            android:layout_marginLeft="@dimen/grid2"
                            android:textSize="24sp"
                            android:layout_weight="1"/>

                        <Button
                            android:id="@+id/pay_inc_up_btn"
                            style="@style/InfoButton"
                            android:layout_width="@dimen/rythm48"
                            android:layout_height="@dimen/rythm48"
                            android:text="+"
                            android:textSize="32sp"
                            android:layout_weight="1"/>

                    </LinearLayout>
                </LinearLayout>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:id="@+id/provider_card_view"
                style="@style/CardView"
                card_view:cardCornerRadius="4dp"
                card_view:cardElevation="6dp">

                <fragment
                    android:id="@+id/provider_fragment"
                    android:name="com.cleartoken.pay.ui.frag.ProviderFragment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                style="@style/CardView"
                card_view:cardCornerRadius="4dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Info"
                        android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/long_text" />
                </LinearLayout>
            </android.support.v7.widget.CardView>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/pay_fab_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/grid2"
        android:clickable="true"
        android:src="@drawable/ic_fab_enabled"
        app:borderWidth="0dp"
        app:layout_anchor="@id/device_info_card"
        app:layout_anchorGravity="bottom|right|end" />

</android.support.design.widget.CoordinatorLayout>

The CardView style.xml snippet:

<style name="CardView">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:layout_margin">@dimen/grid1</item>
</style>

Note:

I use this same Card style universally. On Act#1 this works* (big difference in that Act#1 does NOT have the Coordinator Layout).

My card XML looks like this universally:

 <android.support.v7.widget.CardView
            android:id="@+id/device_info_card"
            style="@style/CardView"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="6dp">
Booger
  • 18,579
  • 7
  • 55
  • 72
  • If you remove the margins from your CardViews, do you still get the crash? – Marko Jul 10 '15 at 11:29
  • Removing margins didn't help - I actually use a style, so it is easy to add/remove this in one place. I updated my code (and included it here) to ensure I am using the CardView universally. Removing the margin attribute from it makes no difference. What is strange, is that this same Card style works on the previous Activity. Dang. – Booger Jul 10 '15 at 13:02
  • Going to comb through the code again - also, it is strange that this is only on 4.4 devices (if there really were a bad margin or padding - it would crash everywhere I would think)...thanks for help! – Booger Jul 10 '15 at 13:03
  • `I need help figuring out what I am doing different then the sample (so my app won't crash)`. What have you tried for debugging? Slowly implement the code until you find the piece that breaks it. – Jared Burrows Jul 10 '15 at 13:45
  • remove `setCompoundDrawablesWithIntrinsicBounds` on your textview inside the cardview and see if it helps – Elltz Jul 13 '15 at 01:40
  • I have determined this is a bug - I can add JUST a CardView to an Activitiy that has a Collapasible Toolbar, and the crash will happen. I will document this well and record the Android bug in the correct place. There is nothing specific with my code I can change to get this fixed (other then completely removing the CardViews. – Booger Jul 17 '15 at 13:54
  • Boo! I was hoping the 22.2.1 release of the support lib would have fixed this, and it didn't. I have figured a work-around, and documented this problem very well, so hopefully this can be fixed in next release. – Booger Jul 17 '15 at 21:51

5 Answers5

5

There is one thing that stands out to me in your stack errors. It seems in 4.4 and below, your app is trying to draw a gui greater than the actual phone width. The RadialGradient error doesn't make sense to me since, it is supposed to be greater than screen size rather than less than zero.

/** Create a shader that draws a radial gradient given the center and radius.
    @param centerX  The x-coordinate of the center of the radius
    @param centerY  The y-coordinate of the center of the radius
    @param radius   Must be positive. The radius of the circle for this gradient.
    @param colors   The colors to be distributed between the center and edge of the circle
    @param stops    May be <code>null</code>. Valid values are between <code>0.0f</code> and
                    <code>1.0f</code>. The relative position of each corresponding color in
                    the colors array. If <code>null</code>, colors are distributed evenly
                    between the center and edge of the circle.
    @param tileMode The Shader tiling mode
*/
public RadialGradient(float centerX, float centerY, float radius,
           @NonNull int colors[], @Nullable float stops[], @NonNull TileMode tileMode) {
    if (radius <= 0) {
        throw new IllegalArgumentException("radius must be > 0");
    }
    if (colors.length < 2) {
        throw new IllegalArgumentException("needs >= 2 number of colors");
    }
    if (stops != null && colors.length != stops.length) {
        throw new IllegalArgumentException("color and position arrays must be of equal length");
    }
    mType = TYPE_COLORS_AND_POSITIONS;
    mX = centerX;
    mY = centerY;
    mRadius = radius;
    mColors = colors;
    mPositions = stops;
    mTileMode = tileMode;
    init(nativeCreate1(centerX, centerY, radius, colors, stops, tileMode.nativeInt));
}

That's a snippet from the radialgradient class. A way to force the code to run would be to simply edit the radialgradient class if you can do that (Android Studio has a way of doing that).

My solution to this problem would be to first go through your xml file and start to remove lines of code that are not common/doesn't make sense. Like:

android:fitsSystemWindows="true"

fitSystemWindow Multiple Calls

Also another thing your should avoid is the weightsum and weight tags for Linear Layout. And try making your parent widget a RelativeLayout.

EDIT:

After thinking for a while (just 2 mins) I realized the error could just be due to the styles.xml implementation. Are you sure you copied all the folders you saw in the git repo?

Sometimes when this errors occur, it's usually because of the values-v21 folder not been added with the appropriate styles.xml.

So If you don't have the values-v21 folder, do this: -Create a values-v21 folder under the res folder. -Then create a styles.xml folder under the values-v21 folder and add this code.

<resources>

<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Community
  • 1
  • 1
Tobi Akerele
  • 962
  • 10
  • 20
  • I removed all the "android:fitsSystemWindows="true", but this had no effect - those attributes are copied from "Cheesesquare", so I didn't think that would be it. I removed the Weighted Linear Layout (visibility="gone, maybe I need to actually remove it) - with no effect. I will continue trying, and thanks so much for your help. – Booger Jul 15 '15 at 13:00
  • @Booger Hey check whether my edit solved your problem, you may need to create a seperate folder system for 4.4.x and lower or something. – Tobi Akerele Jul 15 '15 at 14:56
  • I really appreciate your additional suggestion, but that didn't help (I did add a V21 folder for a themes.xml file already, and added the new styles.xml). I will double check the Cheesesquare implementation, as I didn't copy all those styles and themes implementations. This is a great suggestion. – Booger Jul 15 '15 at 19:53
  • Thanks for your help (enjoy your bounty ;-)). I am just going to start from scratch with an empty Activity, and then add all my views back one at a time. When I debug, I see this error is being thrown during the doInBackground(String... params) method of an AsyncTask that gets the data to use on the Views (it IS still throwing that same Stack relating to the GradientDrawable). This is a strange one for sure, and I will report back when I finally figure it out. – Booger Jul 15 '15 at 21:43
  • @Booger Thanks for that, I wish I could have helped more, hopefully you get your desired result. And thanks for the bounty – Tobi Akerele Jul 17 '15 at 03:28
3

For future people, I found my issue - the Style I was using had the same name as another Style used by the framework (CardView).

I changed the name of this in my styles.xml file to something else (MyCardView) and the crash went away.

In hindsight, I was causing a regression by using that common name.

Booger
  • 18,579
  • 7
  • 55
  • 72
1

According to CardView's Doc:

Before L, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on top and bottom.

Since padding is used to offset content for shadows, you cannot set padding on CardView. Instead, you can use content padding attributes in XML or setContentPadding(int, int, int, int) in code to set the padding between the edges of the Card and children of CardView.

Check all wrap-parent values. I think some where in your code is changing this padding behavior which caused mCornerRadius < 0 in buildShadowCorners method in RoundRectDrawableWithShadow.java.

These links maybe help:

width and height must be > 0 error

Android CardView padding and minHeight

CardView inside RecyclerView has extra margins

Community
  • 1
  • 1
Hana Bzh
  • 2,212
  • 3
  • 18
  • 38
  • Thanks so much, I double checked all my layout attributes, and they have nothing strange (wrap_content everywhere). I am not adding any additional padding in XML (double checking Java now). Thanks so much for the SO links as well! – Booger Jul 10 '15 at 13:04
1

I had the same issue and I found that I had app:cardCornerRadius="0dp" on cardview attributes. When I removed it then my problem solved. Hope this helps

Ramin Rabii
  • 359
  • 4
  • 14
1

I have adater with the item main container as cardview and i had the cardCornerRadius set to 0 :

app:cardCornerRadius="0dp"

I changed it to :

app:cardCornerRadius="1dp"

It worked perfectly now.

I also tested with and without android:fitsSystemWindows="true" , it did NOT change anything for me.

MBH
  • 16,271
  • 19
  • 99
  • 149