29

I've read about it already, but still it's here.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".TaskEditActivity" >

So, the exception java.lang.RuntimeException: Binary XML file line #34: You must supply a layout_width attribute.

Attribute is there, schema too... Solution?

3
  • 5
    clean and rebuild? And post the whole layout
    – Blackbelt
    Jun 8, 2013 at 11:25
  • 4
    I am sure that one of the child views in your layout will be missing a layout width attribute.. please cross check,,
    – amalBit
    Jun 8, 2013 at 11:27
  • Can you post your entire XML file please?
    – MrByte
    Jun 8, 2013 at 11:51

8 Answers 8

61

Also i recommend check your dimens. You may have layout width in dimens, you go to it and you have value like "150" not "150dp" (missing dp) also cause this (that was my case)

3
  • I had the width in dimens, but everything is there and correct, and it's happening occasionally not always Nov 8, 2018 at 14:34
  • Thanks man you save my day. It took me 2 days searching for this bug
    – Tam Huynh
    Mar 18, 2019 at 5:27
  • Thanks for your input. It is a hard to find run-time-only error and hard to notice as well.
    – Simmam
    Dec 25, 2020 at 5:38
8

I had a dimension for a given width but it wasn't present in the default dimens.xml

res/
   values-w320dp/
          dimens.xml -> ring_radius=5dp
   values/
          dimens.xml -> missing ring_radius
2
  • which device you saw this?
    – Aada
    Aug 8, 2018 at 9:14
  • which device you saw this?Isn't this weird and completely contradictory to smallest width configuration. It should have picked righteously from 320 dp.
    – Aada
    Aug 8, 2018 at 9:24
6

It's clear. Child elements missed layout_width attribute.

0
4

For me it was having an extra attribute on one of my view groups (scrollview):

xmlns:android="http://schemas.android.com/apk/res/android"

After that there was I forgot to change my casting of EditText to TextView:

Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText

3

Your problem is not in this layout element, its on the inner one, take a look at line number 34. There is is another user interface element that lacks the layout_width attribute.

2

This can happen if you apply or don't apply the correct theme on a fragment/activity.

For example Leanback's OnboardingSupportFragment requires Theme.Leanback.Onboarding, which you have to apply either on the activity in the manifest android:theme="@style/Theme.Leanback.Onboarding" or in the fragment overriding onProvideTheme()

@Override
public int onProvideTheme() {
    return R.style.Theme_Leanback_Onboarding;
}
1

For me, inside one of my layout.xml files, I had

<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="@string/default_picture_size"
    android:layout_height="@string/default_picture_size"
    android:layout_weight="1"
    android:background="@drawable/tile"
    android:onClick="mClickMethod" >
</ImageView>

and inside strings.xml, I had wrap_content

and so it was showing this in Android Studio:

<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/tile"
    android:onClick="mClickMethod" >
</ImageView>

I thought everything would work because there were no errors and the application compiled and ran. However, there was a run time error that said I didn't set the layout_width.

Once I changed layout_width and layout_height from:

android:layout_width="@string/default_picture_size"
android:layout_height="@string/default_picture_size"

to

android:layout_width="wrap_content"
android:layout_height="wrap_content"

everything worked.

0

just incase all the solutions don't work
clean project -> run cheers

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.