简体   繁体   English

如何在 android 工作室中修复此错误?

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

So whenever i create new project in Android Studio this happens: there is 4 errors in activity_main.xml and 6 errors in AndroidManifest.xml因此,每当我在 Android Studio 中创建新项目时,都会发生这种情况:activity_main.xml 中有 4 个错误,AndroidManifest.Z0F635D0E0F3874FFF8B581C132E6C7A7 中有 6 个错误

this is activity_main这是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>

and this is Mainfest这是 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>

Remove the single quotes from your activity_main.xml file:从您的 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>

You just need to enable embedded Maven repository.您只需要启用嵌入式 Maven 存储库。 To do it follow this path:要做到这一点,请遵循以下路径:

File -> settings ->Build,Execution, Deployment -> Gradle -> Android Studio文件 -> 设置 -> 构建、执行、部署 -> Gradle -> Android Studio

and finally check Enable embedded Maven repository最后检查启用嵌入式 Maven 存储库

Good luck new contributor;)祝新贡献者好运;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM