Alex Alex - 14 days ago 6
Android Question

How to fix a runtime error "You must supply a layout_width attribute." in android?

I have an android app which compiles in AndroidStudio, but when I call a certain activity I get the following error:

11-22 16:08:40.461 13796-13796/com.impyiablue.stoxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.impyiablue.stoxx, PID: 13796
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.impyiablue.stoxx/com.impyiablue.stoxx.EditEntryActivity}: java.lang.RuntimeException: Binary XML file line #25: You must supply a layout_width attribute.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5272)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
Caused by: java.lang.RuntimeException: Binary XML file line #25: You must supply a layout_width attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:606)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6422)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6591)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1866)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1778)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:62)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.impyiablue.stoxx.EditEntryActivity.onCreate(EditEntryActivity.java:51)
at android.app.Activity.performCreate(Activity.java:5977)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365) 
at android.app.ActivityThread.access$800(ActivityThread.java:148) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5272) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) 
11-22 16:10:02.231 15805-15805/com.impyiablue.stoxx:remote E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.impyiablue.stoxx:remote, PID: 15805
java.lang.NumberFormatException: Invalid float: "N/A"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:164)
at java.lang.StringToReal.parseFloat(StringToReal.java:323)
at java.lang.Float.parseFloat(Float.java:306)
at com.impyiablue.stoxx.Tools.ServiceStock$ResponseListener.onResponse(ServiceStock.java:86)
at com.impyiablue.stoxx.Tools.ServiceStock$ResponseListener.onResponse(ServiceStock.java:71)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5272)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)


The corresponding xml file can be found here. I do not see any problems with this xml file. So how to fix the problem? I also did a clean before the latest build...

Answer

Look at line 25 of your XML layout, the TextView with the textTitleEdit ID is missing the layout_width and layout_height attributes, which are required. The next TextView is missing the same attributes as well.