Posts

Showing posts with the label kotlin

POST fails with Retrofit (connect timed out) but works with Postman [on hold]

Image
POST fails with Retrofit (connect timed out) but works with Postman [on hold] SOLVED: stupid mistake, I had https://foo.foo.com:433 instead of https://foo.foo.com:443... I've implemented Retrofit and I'm trying to send a POST request with JSON data as JsonObject. It's not working and I get a failure "connect time out", but I can send a POST request without problem via Postman. At first I thought it was because of the header, I've tried with an Interceptor and to use @Header instead of @Headers. Thank you for your help. Postman Log from HttpLoggingInterceptor() Jun 30, 2018 10:22:09 AM okhttp3.internal.platform.Platform log INFO: --> POST https://foo.foo.com:433/ Jun 30, 2018 10:22:09 AM okhttp3.internal.platform.Platform log INFO: Content-Type: application/json Jun 30, 2018 10:22:09 AM okhttp3.internal.platform.Platform log INFO: Content-Length: 132 Jun 30, 2018 10:22:09 AM okhttp3.internal.platform.Platform log INFO: Jun 30, 2018 10:22:09 AM okhttp3.inter...

Why hasn't the string been replaced when it is from string resource file in Kotlin?

Image
Why hasn't the string been replaced when it is from string resource file in Kotlin? When I use Code A, I get the original string ,why? Code B can replace string both ${myObject.status} and ${myObject.name} , the result is OK. ${myObject.status} ${myObject.name} Image Code A <string name="DetailsOfWiFiDef">The WiFi status is ${myObject.status}, the name of WiFi is ${myObject.name}nn </string> val myObject=getIt() val s=mContext.getString(R.string.DetailsOfWiFiDef) val sb = StringBuilder() sb.append(s) //The string keep original Code B val myObject=getIt() val k="The WiFi status is ${myObject.status},the name of WiFi is ${myObject.name} n" val sb = StringBuilder() sb.append(k) //It has been replaced 1 Answer 1 Kotlin compiler converts string literals into StringBuilder chain at compile time: StringBuilder // code in Kotlin val k = "Th...

How to set a Kotlin while loop stop after 3 times?

How to set a Kotlin while loop stop after 3 times? I'm new to Kotlin, I want to condition my while loop stop after 3 times, please, help! Also it should ask user to quit game or continue val randomNumber: String = Random().nextInt(10).toString() var guess= true println("Welcome to the Number Guess Game") println("Please guess number between 1 to 10") do{ val User=readLine()!!.toString() if(User==randomNumber){ guess=false } else{"Sorry Please Try Again"} }while(guess) println("Congratulation You have guessed the right number.") Here is a link to the Kotlin control flow documentation. Check out the for loop, and the concept of break . – MoxieBall Jun 29 at 22:19 break 1 Answer 1 Try this....