android - Android Studio 无法启动约束布局
问题描述
[在此处输入图像描述]
在右上角,缩放按钮旁边会出现一个蓝色警告,基本上说:
未能启动一门或多门课程
无法实例化以下类:
- android.support.constraint.ConstraintLayout
异常详情:
异常详情 java.lang.NoClassDefFoundError: android/support/constraint/R$styleable android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:599) android.support.constraint.ConstraintLayout.(ConstraintLayout.java:576) java. lang.reflect.Constructor.newInstance(Constructor.java:423) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) android.view.LayoutInflater.inflate(LayoutInflater.java:492) android.view.LayoutInflater.inflate( LayoutInflater.java:394)
并且也是activity_main.xml的文本格式
<?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=".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" />
</android.support.constraint.ConstraintLayout>
在 tools:context=".MainActivity" 行上 .MainActivity 以红色显示“未解决的类 MainActivity”
这是我的 AndroidManifest.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kaan.asd">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我是 Android Studio 的新手,我已经尝试解决这个问题已经有一段时间了,我尝试过清除缓存、清理/重建项目,但都没有解决我的问题。我在 Windows 上使用带有 4.10.1 gradle 版本的 Android Studio 3.3.1 版本。如果有人可以帮助我修复它,我会很高兴。
解决方案
您必须在 android 目录中添加约束布局的存储库:app/build.gradle,如下所示:
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
然后同步您的项目并享受这个完美的布局。
推荐阅读
- javascript - Angular 7,没有 NgModel 如何取复选框状态(真/假)?
- rest - ReST (HTTP) 是否与向许多客户端应用程序广播数据相关
- laravel - 如何有效地重构 laravel 应用程序代码
- python - 将缺少的日期时间列添加到分组数据框中
- c# - 无法使用 Mono.Cecil 0.10.2 获取指令的行号
- ios - 不能在额外的类中外包 UICollectionViewDatasource
- spring-boot - 多个 @EnableBinding 与 Kafka Spring Cloud Stream
- c# - 将视图从一个控制器传递到另一个控制器的视图
- ruby-on-rails - 如果轨道中的 X 或 Y 条件
- c# - 每次更改字段时如何使用 NotifyPSEvent 触发事件?