android - 调用 createView 失败,如何修复 xml 中的 android 屏幕预览无法在 intellij 中正确显示
问题描述
我对 android 相当陌生,一旦我创建了一个新的 Android 项目并更新了所有依赖项,我就开始面临 xml 预览的设计选项卡中未正确呈现的问题。有一个错误说Call to createView failed
。我在下面附上了一张快照。
这是我的build.gradle
文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "io.github.animeshz.airbent_android"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
android.sourceSets {
androidTest.java.srcDirs += "src/androidTest/kotlin"
// debug.java.srcDirs += "src/debug/kotlin"
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3"
implementation "io.ktor:ktor-client-android:$ktor_version"
}
这是我的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
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>
在xml编辑器中弹出的错误详细信息下:
java.lang.AssertionError: Call to createView failed
at android.view.BridgeInflater.lambda$createViewFromCustomInflater$0(BridgeInflater.java:269)
at android.view.BridgeInflater.createViewFromCustomInflater(BridgeInflater.java:286)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:124)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:310)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:323)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:200)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:572)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:698)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
任何帮助,将不胜感激!
解决方案
因此 Intellij IDE 建议更新的最新版本的依赖项存在问题。我恢复到这四个依赖项的旧版本:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
并在下面打开Show Layout Decorations
附加快照:
这解决了这个问题。如果他/她遇到同样的问题,希望其他人会发现这很有用!
推荐阅读
- node.js - 如何在 .BOT 文件中更改聊天机器人的 LUIS 应用程序?
- server - VPS Server INSIDE China - 主机推荐?
- layout - 不要在 GOJS 中为 ForceDirectedLayout 重叠节点
- javascript - C# 如何将复杂 JSON 对象的子对象转换为模型
- vue.js - 迭代时没有得到不同的类名
- asp.net-mvc - 我想在 mvc 的服务器路径中下载我的 Pdf 文件,请任何人指导我...用代码
- python - Boto3 使用 django 应用程序在本地和弹性 beantalk 上生成不同的链接
- ios - NSGenericException:此编码器要求从 initWithCoder 返回替换的对象
- angular - 通过按钮单击添加行
- c# - 多因素认证获取Sharepoint ClientContext后如何获取ProjectContext?