Leanback Sample Activity Crashes

1.2k views Asked by At

I have added a leanback sample activity from android studio. The activity crashes with following stacktrace. I have not modified the code and I see that all the layouts added by default does have the layout_width and layout_height parameters defined.

java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute.
     at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:608)
     at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6485)
     at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6654)
     at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:741)
     at android.support.v17.leanback.widget.BaseCardView$LayoutParams.<init>(BaseCardView.java:862)
     at android.support.v17.leanback.widget.BaseCardView.generateLayoutParams(BaseCardView.java:817)
     at android.support.v17.leanback.widget.BaseCardView.generateLayoutParams(BaseCardView.java:54)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
     at android.support.v17.leanback.widget.ImageCardView.buildImageCardView(ImageCardView.java:165)
     at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:156)
     at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:282)
     at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:275)
     at com.amazon.bueller.photos.activity.CardPresenter$1.<init>(CardPresenter.java:55)
     at com.amazon.bueller.photos.activity.CardPresenter.onCreateViewHolder(CardPresenter.java:55)
     at android.support.v17.leanback.widget.ItemBridgeAdapter.onCreateViewHolder(ItemBridgeAdapter.java:312)
     at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6290)
     at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5478)
     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5363)
     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5359)
     at android.support.v17.leanback.widget.GridLayoutManager.measureScrapChild(GridLayoutManager.java:1211)
     at android.support.v17.leanback.widget.GridLayoutManager.processRowSizeSecondary(GridLayoutManager.java:1277)
     at android.support.v17.leanback.widget.GridLayoutManager.onMeasure(GridLayoutManager.java:1374)
     at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3012)
     at android.view.View.measure(View.java:17935)
     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5548)
     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
     at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
     at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
     at android.view.View.measure(View.java:17935)
     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5548)
     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
     at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
     at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
     at android.view.View.measure(View.java:17935)
     at android.support.v17.leanback.widget.GridLayoutManager.measureChild(GridLayoutManager.java:1466)
     at android.support.v17.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1556)
     at android.support.v17.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:111)
     at android.support.v17.leanback.widget.Grid.appendVisibleItems(Grid.java:371)
     at android.support.v17.leanback.widget.GridLayoutManager.appendVisibleItems(GridLayoutManager.java:1749)
     at android.support.v17.leanback.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:1973)
     at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3506)
     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3254)
     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3767)
     at android.view.View.layout(View.java:16046)
                                                                        at android.view.ViewGroup.layout
1

There are 1 answers

4
ABS On BEST ANSWER

Add 'Theme.Leanback' as style to activity and the error will go away.

Example:

<activity android:name="com.sample.activity.DetailsActivity"
              android:theme="@style/Theme.Leanback"/>