簡體   English   中英

如何在 android 工作室中修復此錯誤?

[英]how can i fix this errors in android studio?

因此,每當我在 Android Studio 中創建新項目時,都會發生這種情況:activity_main.xml 中有 4 個錯誤,AndroidManifest.Z0F635D0E0F3874FFF8B581C132E6C7A7 中有 6 個錯誤

這是activity_main

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"`    <---ERROR(attribute android:layout_width is not allowed here)
`android:layout_height="match_parent"`    <---ERROR(attribute android:layout_height is not allowed )
`tools:context=".MainActivity">`      <---ERROR(attribute tools:context is not allowed here)

`<TextView`    <---ERROR(attribute TextView is not allowed here)


    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

這是 Mainfest

<application
android:allowBackup="true"<--ERROR(attribute android:allowBackup is not allowed here)
`android:icon="@mipmap/ic_launcher"`  <--ERROR(attribute android:icon is not allowed here)
android:label="@string/app_name"
`android:roundIcon="@mipmap/ic_launcher_round"` <--ERROR(attribute android:roundIcon is not ...)
`android:supportsRtl="true"`  <--ERROR(attribute android:supportsRtl is not ...)
`android:theme="@style/AppTheme">`  <--ERROR(attribute android:theme is not allowed..)
    `<activity android:name=".MainActivity">` <--ERROR(Unresolved class MainActivity)


     <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

從您的 activity_main.xml 文件中刪除單引號:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

您只需要啟用嵌入式 Maven 存儲庫。 要做到這一點,請遵循以下路徑:

文件 -> 設置 -> 構建、執行、部署 -> Gradle -> Android Studio

最后檢查啟用嵌入式 Maven 存儲庫

祝新貢獻者好運;)

暫無
暫無

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

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