android - 如何在 android studio 中修复此错误?
问题描述
因此,每当我在 Android Studio 中创建新项目时,都会发生这种情况:activity_main.xml 中有 4 个错误,AndroidManifest.xml 中有 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>
推荐阅读
- windows - Gradle:无法连接到 Windows 上的 Kotlin 守护程序
- wpf - 如何绕圆旋转直线的终点,同时保持起点固定。在 WPF 中
- qt5 - 在某些窗口管理器上关闭 Qt5 应用程序时出现段错误
- c++ - 如何在 gtkmm3 中动态命名小部件变量?
- javascript - 未捕获的类型错误:无法设置未定义的属性“isEditMode”
- java - 我们如何在单行中打印循环输出?
- ios - 如何在不遇到无限循环的情况下调整 NSError 初始化
- android - 使用 volley 和 json 未提供的图像解析 json
- ios - 使用后台上下文时无法在不同上下文中的对象之间建立关系
- python - 混合对象类型列和管理重复项