简体   繁体   中英

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

this is 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

<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:

<?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. To do it follow this path:

File -> settings ->Build,Execution, Deployment -> Gradle -> Android Studio

and finally check Enable embedded Maven repository

Good luck new contributor;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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