kotlin

Why do I get this? Kotlin: Type mismatch: inferred type is String? but String was expected

旧时模样 提交于 2021-01-04 05:40:06
问题 When I try to run this code: fun main() { val input: String = readLine() val outputs = input.toCharArray() for (i in 0 until input.length) { print("${outputs[i]}${outputs[i]}") } } I get this Error:(2, 25) Kotlin: Type mismatch: inferred type is String? but String was expected. How do I fix that? 回答1: The readLine() function returns a String? (nullable String). Return the line read or null if the input stream is redirected to a file and the end of file has been reached. There is no end of

Why do I get this? Kotlin: Type mismatch: inferred type is String? but String was expected

回眸只為那壹抹淺笑 提交于 2021-01-04 05:38:31
问题 When I try to run this code: fun main() { val input: String = readLine() val outputs = input.toCharArray() for (i in 0 until input.length) { print("${outputs[i]}${outputs[i]}") } } I get this Error:(2, 25) Kotlin: Type mismatch: inferred type is String? but String was expected. How do I fix that? 回答1: The readLine() function returns a String? (nullable String). Return the line read or null if the input stream is redirected to a file and the end of file has been reached. There is no end of

Why do I get this? Kotlin: Type mismatch: inferred type is String? but String was expected

孤者浪人 提交于 2021-01-04 05:38:10
问题 When I try to run this code: fun main() { val input: String = readLine() val outputs = input.toCharArray() for (i in 0 until input.length) { print("${outputs[i]}${outputs[i]}") } } I get this Error:(2, 25) Kotlin: Type mismatch: inferred type is String? but String was expected. How do I fix that? 回答1: The readLine() function returns a String? (nullable String). Return the line read or null if the input stream is redirected to a file and the end of file has been reached. There is no end of

kotlin object declaration inject class

霸气de小男生 提交于 2021-01-04 04:39:17
问题 i am using kotlin + springboot to build my web application. i want to create a tool class ,so i coded like above: @Service object XXXUtil{ @Autowired lateinit var restTemplate: RestTemplate @Autowired lateinit var objectMapper: ObjectMapper ... } but after i started the application, resTemplate cannot be injected. kotlin.UninitializedPropertyAccessException: lateinit property restTemplate has not been initialized is it because that object declaration does not allow injection or i code in a

kotlin object declaration inject class

帅比萌擦擦* 提交于 2021-01-04 04:38:25
问题 i am using kotlin + springboot to build my web application. i want to create a tool class ,so i coded like above: @Service object XXXUtil{ @Autowired lateinit var restTemplate: RestTemplate @Autowired lateinit var objectMapper: ObjectMapper ... } but after i started the application, resTemplate cannot be injected. kotlin.UninitializedPropertyAccessException: lateinit property restTemplate has not been initialized is it because that object declaration does not allow injection or i code in a

To draw rounded rectangle in Android

家住魔仙堡 提交于 2021-01-04 04:23:30
问题 I have found this question and the solution was this code : <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#ffffff" /> <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" android:topLeftRadius="8dp" android:topRightRadius="8dp" /> </shape> This code doesn't work on my PC (no rounded corners). And you ? There has been changes ? EDIT 1: I have an error when I build the project : AAPT: error: XML or text

To draw rounded rectangle in Android

寵の児 提交于 2021-01-04 04:19:10
问题 I have found this question and the solution was this code : <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#ffffff" /> <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" android:topLeftRadius="8dp" android:topRightRadius="8dp" /> </shape> This code doesn't work on my PC (no rounded corners). And you ? There has been changes ? EDIT 1: I have an error when I build the project : AAPT: error: XML or text

Android LiveData in androidTest returns null

做~自己de王妃 提交于 2021-01-04 03:23:28
问题 I'm running an androidTest instrumentation test and I have a method that returns LiveData from a DAO object using Room. I'm calling the method like so: val animal = roomDatabase.animalsDao().getAnimal(1) animal.observeForever(mMockObserver) assertNotNull(animal.value) I used Mockito to mock the observer: @Mock private lateinit var mMockObserver = Observer<Animal> This should return an instance of LiveData containing the Animal at id 1, but it's null. It's my understanding that in order for

How to make android app as server and python as client side

孤人 提交于 2021-01-04 03:13:08
问题 Description So basically i am building an android app in which i am using kotlin and which will behave as server.Whilst on the client side i am using python.I am using sockets for this purpose.I have to communicate using UDP.But i am unable to make connection to my android app.In python script sock.connect(('10.0.2.2', 6000)) i have also tried placing the emulator ip instead of localhost.I just want to send and receive simple messages. Another Issue: Python script just times out it does not

How to make android app as server and python as client side

回眸只為那壹抹淺笑 提交于 2021-01-04 03:10:49
问题 Description So basically i am building an android app in which i am using kotlin and which will behave as server.Whilst on the client side i am using python.I am using sockets for this purpose.I have to communicate using UDP.But i am unable to make connection to my android app.In python script sock.connect(('10.0.2.2', 6000)) i have also tried placing the emulator ip instead of localhost.I just want to send and receive simple messages. Another Issue: Python script just times out it does not