簡體   English   中英

Android Studio:嘗試在第0行上運行App,Supply_width屬性時出錯?

[英]Android Studio: Error when trying to run App, Supply_width attribute on line 0?

我似乎無法弄清楚為什么我的應用程序無法運行...我嘗試使所有程序無效並重新啟動,重建項目,並將布局寬度應用於所有內容,但仍然無法正常工作。 有什么要解決的問題嗎? 我真的對第0行問題的layout_width屬性感到困惑,到目前為止還無法弄清楚。

Logcat:

01-30 21:53:01.964 4622-4622/test.pkg.miclass.decode E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: test.pkg.miclass.decode, PID: 4622
                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{test.pkg.miclass.decode/test.pkg.miclass.decode.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: You must supply a layout_width attribute.
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                          at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                                                                       Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: You must supply a layout_width attribute.
                                                                       Caused by: java.lang.UnsupportedOperationException: Binary XML file line #0: You must supply a layout_width attribute.
                                                                          at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:775)
                                                                          at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7554)
                                                                          at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7746)
                                                                          at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1976)
                                                                          at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1874)
                                                                          at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1872)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                          at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                          at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                          at test.pkg.miclass.decode.MainActivity.onCreate(MainActivity.java:18)
                                                                          at android.app.Activity.performCreate(Activity.java:6999)
                                                                          at android.app.Activity.performCreate(Activity.java:6990)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                                                                          at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6494)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

這是我到目前為止的xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="383dp"
    android:layout_height="510dp"
    tools:context="test.pkg.miclass.decode.MainActivity">

    <LinearLayout
        android:layout_width="363dp"
        android:layout_height="55dp"
        android:orientation="horizontal"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Text:"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

        <EditText
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="54dp"
        android:orientation="horizontal"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="75dp">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="KeyPhrase:"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

        <EditText
            android:id="@+id/keyphrase"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="55dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="136dp">

        <RadioGroup
            android:id="@+id/encryptGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".7"
            android:gravity="center">

            <RadioButton
                android:id="@+id/encrypt"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:checked="true"
                android:text="Encrypt" />

            <RadioButton
                android:id="@+id/decrypt"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="RadioButton"
                tools:text="Decrypt" />
        </RadioGroup>

    </LinearLayout>

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="68dp"
        android:orientation="horizontal"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="207dp">

        <Button
            android:id="@+id/runButton"
            style="@style/Widget.AppCompat.Button"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Run" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="63dp"
        android:orientation="horizontal"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="285dp">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Results:"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

        <EditText
            android:id="@+id/result"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

任何幫助將不勝感激!

將寬度分配給按鈕-:

添加此行-:

android:layout_width="wrap_content"

<Button
            android:id="@+id/runButton"
            style="@style/Widget.AppCompat.Button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Run" />

您聲明兩個具有相同ID的android:id =“ @ + id / textView2”

 <Button
                android:id="@+id/runButton"
                style="@style/Widget.AppCompat.Button"
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:text="Run"/>

視野中

 <Button
        android:id="@+id/runButton"
        style="@style/Widget.AppCompat.Button"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Run" />

您添加以下行android:layout_width="wrap_content"示例:

<Button
            android:id="@+id/runButton"
            style="@style/Widget.AppCompat.Button"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:text="Run" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM