gpt4 book ai didi

android - 尝试使用 Anko verticalLayout 时出现 EOFException

转载 作者:行者123 更新时间:2023-11-29 00:53:20 26 4
gpt4 key购买 nike

关注 tutorial ,我通过在应用程序模块中添加 build.gradle 来导入 Anko 库:

implementation "org.jetbrains.anko:anko-sdk25:0.10.5"
implementation "org.jetbrains.anko:anko-appcompat-v7:0.10.5"

我试试这个例子:

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import org.jetbrains.anko.*

class StartActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {

verticalLayout {
editText {
hint = "Enter your name"
}
button("ECHO"){
setOnClickListener {
toast("Button clicked")
}
}
}
}
}

出于某种原因,`import org.jetbrains.anko.* 变得很棒,AndroidStudio 通过将其置于红色下方来显示 verticalLayout 的错误。当我将鼠标悬停在它上面时,出现错误:

java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion$Companion.readFrom(BuiltInsBinaryVersion.kt:29)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment.readProto(MetadataPackageFragmentProvider.kt:136)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment.computeMemberScope(MetadataPackageFragmentProvider.kt:105)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment.access$computeMemberScope(MetadataPackageFragmentProvider.kt:72)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment$memberScope$1.invoke(MetadataPackageFragmentProvider.kt:96)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment$memberScope$1.invoke(MetadataPackageFragmentProvider.kt:72)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:346)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:402)
at org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment.getMemberScope(MetadataPackageFragmentProvider.kt:128)
at org.jetbrains.kotlin.descriptors.impl.LazyPackageViewDescriptorImpl$memberScope$1.invoke(LazyPackageViewDescriptorImpl.kt:46)
at org.jetbrains.kotlin.descriptors.impl.LazyPackageViewDescriptorImpl$memberScope$1.invoke(LazyPackageViewDescriptorImpl.kt:30)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:346)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:402)
at org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter.getWorkerScope(LazyScopeAdapter.kt:23)
at org.jetbrains.kotlin.resolve.scopes.AbstractScopeAdapter.getContributedClassifier(AbstractScopeAdapter.kt:44)
at org.jetbrains.kotlin.descriptors.FindClassInModuleKt.fin...

我该怎么做才能不再引发此错误?

最佳答案

尝试将您的导入更改为以下内容:

import org.jetbrains.anko.button
import org.jetbrains.anko.editText
import org.jetbrains.anko.toast
import org.jetbrains.anko.verticalLayout

这对我来说很好用:enter image description here

它还会编译和运行:(删除一些工具栏,因为它有一个项目名称)

enter image description here

这是我的依赖项列表,这是一个全新的项目,所以一切都是默认的:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.anko:anko-sdk25:0.10.5"
implementation "org.jetbrains.anko:anko-appcompat-v7:0.10.5"
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

即使将其更改为您发布的内容,对我也适用:

enter image description here

可能与您的 kotlin 版本或 android studio 错误有关,尝试更新您的 IDE,对于我正在使用的这个默认项目

Gradle: 3.4.0
Kotlin: 1.3.31

和这个版本的android studio(希望这有帮助):

Android Studio 3.4
Build #AI-183.5429.30.34.5452501, built on April 10, 2019
JRE: 1.8.0_152-release-1343-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6

旁注:我意识到 OP 没有 setContentView 所以我想我也必须尝试一下,但是:

enter image description here enter image description here

关于android - 尝试使用 Anko verticalLayout 时出现 EOFException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57409310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com