EOFException when trying to use Anko verticalLayout Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of EOFException when trying to use Anko verticalLayout without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Following a tutorial, I imported the Anko libaries by adding in my build.gradle in the app module:

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

I try the example:

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")
                }
            }
        }
    }
}

For someone reason `import org.jetbrains.anko.* gets great out and AndroidStudio shows an error for verticalLayout by underlying it red. When I hover over it I get the error:

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...

What do I have to do, so that this error isn’t thrown anymore?

Answer

try changing your imports to the following :

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

this works fine for me: enter image description here

and it also compiles and runs: (cutting out some of the toolbar as it has a project name in it)

enter image description here

here’s a list of my dependencies, this is a brand new project from scratch so everything is default :

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'
}

even changing it to what you posted, works for me as well:

enter image description here

Might be related to either your version of kotlin or maybe an android studio bug, try updating your IDE, for this default project I’m using

Gradle: 3.4.0
Kotlin: 1.3.31

and this version of android studio (hope this helps):

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

Side note: I realized OP has no setContentView so I figured I had to try that as well, however:

enter image description here enter image description here

We are here to answer your question about EOFException when trying to use Anko verticalLayout - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji