kotlin

Kotlin - fragment lifecycle navigation issues; why does child fragment become current destination?

匆匆过客 提交于 2021-01-29 09:17:25
问题 Kotlin/Android novice. Please bear with me. My app has the following navigation scheme: BottomNavigationView with navigationController where fragment One, Two and Three are "top destinations", from which I look to navigate further down in the navigation hierarchy. I implemented the scheme following this video tutorial. MY ISSUE Fragment Three is a QR-code scanner. Upon successful scan I aim to navigate to fragment X. However, when I reach the point of navigation, fragment X has become

How to disable @NonNull/@Nullable annotations in Kotlin generated Java code

不问归期 提交于 2021-01-29 09:11:40
问题 I need to disable @NonNull/@Nullable annotations in Kotlin generated Java code because some annotation adapters (code generators) cant handle properly some annotated fields Do you know how it could be done? Some Kotlin annotation or compilator directive Problem: kotlin class: open class TestModel( var test: ByteArray = ByteArray(0) ) generated java: public class TestModel { @org.jetbrains.annotations.NotNull() private byte[] test; @org.jetbrains.annotations.NotNull() public final byte[]

How shoul I test logic that contains calls to aquire current date?

家住魔仙堡 提交于 2021-01-29 08:52:12
问题 For example, I have this Kotlin class and method (Spring-managed class if it matters): import org.springframework.stereotype.Service import java.time.LocalDateTime data class TestObj( val msg: String, val dateTime: LocalDateTime ) @Service class TestAnotherService { fun doSmthng1(testObj: TestObj) { println("Oh my brand new object : $testObj") } } @Service class TestService( private val testAnotherService: TestAnotherService ) { fun doSmthng() { testAnotherService.doSmthng1(TestObj("my

How can I retrieve the errorBody sent from server on retrofit error handler?

99封情书 提交于 2021-01-29 08:31:13
问题 When everything goes well, I can retrieve the body from response.body() with no problem. Althought, when a validation error occurs on server (in my case, duplicated email) it sends the error to frontend and when I try to access the error body response.errorBody() the following info is retrieved: "E/API Activity: onResponse: PostSalao okhttp3.ResponseBody$1@84d856e" I expected to get something like "error: email already used" . As you may see on this video on (10:08), he does the same thing I

Unable to change an object property in MutableList

廉价感情. 提交于 2021-01-29 08:27:05
问题 I'm trying to change quantity in my MutableList of an Object if there is yet that object with same ID in the list, the issue is that i'm getting bunch of errors when trying to do it.qty += qty Here is a screen of what android studio is saying: If it would be useful here is my Articolo class code: data class Articolo(var barcode: String, var qta: Number) { constructor() : this ("", 0) } And the code from the screenshot: private var articoli = mutableListOf<Articolo>() articoli.find{ it.barcode

@spy Mockito for map or switchMap livedata

限于喜欢 提交于 2021-01-29 08:20:39
问题 I have a map liveData in view model. val isOpen: LiveData<Boolean> = Transformations.map(shouldTry) { println("in map") close() false } fun open() { println("open called") } how can use @spy for open called or not? @Test fun test() :runBlockingTest{ viewModel = spy(ViewModel()) // Action viewModel.shouldTry.value = true // Expected verify(viewModel).open() } 来源: https://stackoverflow.com/questions/64444828/spy-mockito-for-map-or-switchmap-livedata

Build failed with an exception error in Kotlin

本秂侑毒 提交于 2021-01-29 08:16:35
问题 Got this error after updating my Kotlin plugin on android studio. package com.example.test fun main(args: Array<String>) { println("Hello world") } This is the error I receive: * Where: Initialization script '/private/var/folders/bn/st769wd16nv1d5_wccw8_tm00000gn/T/Test_main__2.gradle' line: 27 * What went wrong: A problem occurred configuring project ': app'. > Could not create task ':app:Test.main()'. > SourceSet with name 'main' not found. When I run a stack trace, this is the response I

How to retrieve a single media file from external storage using Mediastore?

巧了我就是萌 提交于 2021-01-29 08:10:14
问题 Before API 29, we could have easily retrieved a media file from external storage using these lines of code. val dirName = Environment.getExternalStorageDirectory().absolutePath + "/$appName/" val fileName = "$appName_$timeStamp.$extension" val dir = File(dirName) val file = File(dir, fileName) But I was unable to find a code snippet which can achieve the same thing using Mediastore API. Since getExternalStorageDirectory is deprecated in API 29, I don't know how to do. I have searched about

How can i solve the Array problem in Kotlin?

半腔热情 提交于 2021-01-29 07:53:50
问题 When I try to compile some basic array code I get errors. I tried to re-install IntelliJ and I made all updates. fun main(args: Array<String>) { val numbers = intArrayOf(1, 4, 42, -3) if (4 in numbers) { println("numbers array contains 4.") } } Here are the errors. Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/KotlinPackage at KtlneKt.main(ktlne.kt:2) at KtlneKt.main(ktlne.kt) Caused by: java.lang.ClassNotFoundException: kotlin.KotlinPackage at java.net.URLClassLoader

BLE Advertise data size limit

百般思念 提交于 2021-01-29 07:42:54
问题 On My Addroid app I'm trying to add some extra data when I try to start ble advertising, and as I've read, advertise data must be <= 31 bytes. That's how I do it: var testData = "abcdefghij" var data = AdvertiseData.Builder().apply { addServiceData( ParcelUuid(MY_UUID), testData.toByteArray(Charsets.UTF_8) ) } bleAdvertiser.startAdvertising( settings.build(), data.build(), advertiseCallback ) In this way everything works well. Now if testData fields become var testData = "abcdefghijk"