我想学习如何构建应用程序,我在网上找到了一个课程,解释了该怎么做。为了这个课程,我下载了javajdk和android studio,并在默认设置下安装了所有内容。从那里我打开了一个空白页面的新项目,我得到了大约9个错误,预览不起作用。我所有的朋友都没有这个问题,我不知道我为什么会这样。这是代码:
<?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="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.android.com/tools
http://schemas.android.com/apk/res/android
http://schemas.android.com/apk/res/android ">
<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" />
</android.support.constraint.ConstraintLayout>
我得到的错误是:
"URI未注册"(前3行(
"此处不允许使用Android_Width/Height/Tools"(这是3个错误(
"无法解析符号http://schemas.android.com/apk/res/android">
"此处不允许元素文本视图">
有人能解释一下并帮我解决这个问题吗?我想开始建设和学习,但我似乎找不到这里的问题。。此外,我还尝试重新安装,重新打开一个项目,将uri添加到schema%dtd列表中,并检查我是否错误地打开了调试xml。该文件是"activitymain.xml"。提前感谢:(
您在app/build.gradle上声明了约束布局吗?
1.确保您在模块级中声明了maven.google.com存储库
build.gradle文件:
repositories {
google()
}
2.将库作为依赖项添加到同一个build.gradle文件中,如下例所示。请注意,最新版本可能与示例中显示的有所不同:
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
}
3.在工具栏或同步通知中,单击"将项目与渐变文件同步"。
参考
当去除所有无用的杂物时,它应该起作用:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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" />
</android.support.constraint.ConstraintLayout>
CCD_ 1的定义有重复和错误的条目。