Unresolved reference for Launch in CoroutineScope(IO).Launch - kotlin

I've read the following, it doesn't answer my question.
Unresolved reference: launch
I'm trying to follow the following tutorial https://www.youtube.com/watch?v=z7lfPYLGE7k for creating a simple socket in Kotlin. Everything is trivial up to this point:
I have:
CoroutineScope(IO).Launch {
client(address, port)
}
However, this gives the error:
Unresolved reference: Launch
It is unclear to me what I should put in my dependencies in build.gradle, I've tried a slew:
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:x.x.x"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:x.x.x"
implementation("androidx.collection:collection-ktx:1.2.0")
implementation("androidx.fragment:fragment-ktx:1.5.4")
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.5.1")
implementation("androidx.navigation:navigation-runtime-ktx:2.5.3")
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
implementation("androidx.palette:palette-ktx:1.0.0")
implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.5.1")
implementation("androidx.room:room-ktx:2.4.3")
implementation("androidx.sqlite:sqlite-ktx:2.2.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
implementation("androidx.work:work-runtime-ktx:2.7.1")
implementation("com.google.android.play:core-ktx:1.8.1")
I also don't understand what I should import, again I've tried probably more than necessary:
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.system.Os.socket
import java.net.Socket
import java.util.*
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import androidx.activity.viewModels
Failing this, I've also tried the following to see if I can call the client() function from these:
viewModelScope.launch {
}
viewLifecycleOwner.lifecycleScope.launch {
}
lifecycleScope.launch {
}
However, they have the same problem.

The method you're looking for is:
CoroutineScope(Dispatchers.IO).launch {
...
}
Without the capitalization in the method name.

Related

MobileElement library cannot be found in java-client-8.2.1-all.jar

How can I add MobileElement libary? I am using java-client-8.2.1-all.jar and I have imported io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
I also added the dependency in app > build.gradle
implementation files('libs/java-client-8.2.1-all.jar')
Any idea?
Thanks

Where to import Ktor Plugin "install" from

I just created a new Ktor project, but following the docs, I am unsure where to import Plugin "install" function.
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.netty.handler.codec.DefaultHeaders
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
install(DefaultHeaders)
install(CallLogging)
install(Koin) {
slf4jLogger()
modules(helloAppModule)
}
configurePlugins()
configureRouting()
}.start(wait = true)
}
My IDE has several suggestions, none of which seem to resolve correctly. I am using Ktor version 2.0.0.
The problem is that you have incorrect Default headers import.
Make sure you have it as dependency:
implementation("io.ktor:ktor-server-default-headers:$ktor_version")
Replace
import io.netty.handler.codec.DefaultHeaders
with
import io.ktor.server.plugins.defaultheaders.*
IDE should suggest you the following import for install:
import io.ktor.server.application.*

IntelliJ missing reference to slf4j in new Ktor project

I started a new Ktor project through their IntelliJ plugin and everything is compiling and running fine with Gradle. However in IntelliJ everything that references the slf4j logger is having a Unresolved reference: ... error.
My import and setting log leve looks like this (sorry my reputation is not high enough to post images):
The project is generated with the following dependencies
// gradle.properties
ktor_version=1.4.0
logback_version=1.2.1
// build.gradle.kts
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-auth:$ktor_version")
implementation("io.ktor:ktor-auth-jwt:$ktor_version")
implementation("io.ktor:ktor-jackson:$ktor_version")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
}
I have tried to add org.slf4j:slf4j-nop:1.7.30 to my dependencies without any luck.
So my questions is, has anyone seen this error before and know if there is a dependency or setting i could change? It is annoying to not have any code completion and errors scattered around the IDE even though it compiles and run fine.
The full application code generated with the Ktor plugin is below if needed:
package com.example
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.features.*
import org.slf4j.event.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.auth.*
import com.fasterxml.jackson.databind.*
import io.ktor.jackson.*
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
#Suppress("unused") // Referenced in application.conf
#kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(CallLogging) {
level = Level.INFO
filter { call -> call.request.path().startsWith("/") }
}
install(Authentication) {
}
install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)
}
}
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
get("/json/jackson") {
call.respond(mapOf("hello" to "world"))
}
}
}
This was a caching issue with Gradle and IntelliJ, probably caused from other project dependencies. To IntelliJ the slf4j-api library was empty. Removing the global Gradle cache with rm -rf ~/.gradle/caches and re-download the dependencies solved the issue for me.

Failed to instantiate class in selenium-cucumber framework

I am using cucumber 3.0.2.My testrunner code is given below.
package futurerx_testrunner_pkg;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features="features/login.feature",glue= {"stepdefinition"})
public class testrunner {
}
I have created 2 packages in src(futurerx_testrunner_pkg and stepdefinition).I have testrunner.java in futurerx_testrunner_pkg package and Basedefinition.java in stepdefinition package.
But when i am running the code,it gives an error "Failed to instantiate class stepdefinition.Basedefinition at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:47) at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33) at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)".
I am new to this cucumber-selenium framework and not understanding where i am going wrong.Thanks in Advance.

Android - Glide ".placeholder" method not recognized

I have a recycler view. In the adapter's onBindViewHolder method I have the following code to load an image:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Log.i("TEST-APP", "Binding View Holder")
Glide.with(context)
.load(items[position])
.placeholder(R.drawable.animated_loading_icon)
.into(holder.imageView)
}
However, Android Studio is saying that "placeholder" is an unresolved reference. This is confusing because the documentation indicates that this is the correct way to load a placeholder.
What am I doing wrong?
Also, here are my imports in the RecyclerViewAdapter class
package com.example.myname.recylerviewtest
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.*
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.recyclerview_item_column.view.*
Lastly, here are my dependencies in build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
api 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
As shown in the Glide documentation:
Most options in Glide can be applied using the RequestOptions class
and the apply() method.
Use request options to apply (among others):
Placeholders
Transformations
Caching Strategies
Component specific options, like encode quality, or decode Bitmap configurations.
So, if you want to use placeholder, you have two options.
One of them is to do it this way:
Glide.with(context)
.load(items[position])
.apply(RequestOptions()
.placeholder(R.drawable.animated_loading_icon)
)
.into(holder.imageView)
And the other option would be to implement the Generated API