kotlin

Moshi + Kotlin + SealedClass

廉价感情. 提交于 2020-07-05 05:44:55
问题 Is there a way of deserializing json using sealed class Layer data class ShapeLayer(var type: LayerType) : Layer data class TextLayer(var type: LayerType) : Layer data class ImageLayer(var type: LayerType) : Layer LayerType is just some enum which can be used to distinguish which type should this object have. I thought I could add Adapter this way: class LayerAdapter{ @FromJson fun fromJson(layerJson: LayerJson): Layer { return when (layerJson.layerType) { LayerType.SHAPE -> PreCompLayer()

Moshi + Kotlin + SealedClass

百般思念 提交于 2020-07-05 05:44:15
问题 Is there a way of deserializing json using sealed class Layer data class ShapeLayer(var type: LayerType) : Layer data class TextLayer(var type: LayerType) : Layer data class ImageLayer(var type: LayerType) : Layer LayerType is just some enum which can be used to distinguish which type should this object have. I thought I could add Adapter this way: class LayerAdapter{ @FromJson fun fromJson(layerJson: LayerJson): Layer { return when (layerJson.layerType) { LayerType.SHAPE -> PreCompLayer()

Moshi + Kotlin + SealedClass

半城伤御伤魂 提交于 2020-07-05 05:44:08
问题 Is there a way of deserializing json using sealed class Layer data class ShapeLayer(var type: LayerType) : Layer data class TextLayer(var type: LayerType) : Layer data class ImageLayer(var type: LayerType) : Layer LayerType is just some enum which can be used to distinguish which type should this object have. I thought I could add Adapter this way: class LayerAdapter{ @FromJson fun fromJson(layerJson: LayerJson): Layer { return when (layerJson.layerType) { LayerType.SHAPE -> PreCompLayer()

IllegalAccessError: Method is inaccessible to class

安稳与你 提交于 2020-07-04 16:35:16
问题 I've got very strange error, because it only happens after installing app from generated .apk . When I try to run the app through IDE, it works fine. java.lang.IllegalAccessError: Method 'int <package>.BaseActivity$Companion.getANIMATION_SLIDE_FROM_RIGHT()' is inaccessible to class '<package>.MyActivity' (declaration of '<package>.MyActivity' appears in /data/app/<package>-mg7eYmJ8hX5WvkNWNZWMVg==/base.apk!classes3.dex) As you can see there is class called BaseActivity which looks like this:

Implicit Intent is not working due to context issue

我只是一个虾纸丫 提交于 2020-07-04 04:26:22
问题 Here is my code :- Favourite Activity import android.content.Context import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.core.content.ContextCompat.startActivity import androidx.recyclerview.widget

android.view.View.systemUiVisibility deprecated. What is the replacement?

你。 提交于 2020-07-03 09:40:01
问题 I have updated the project target API version to 30, and now I see that the systemUiVisibility property is deprecated. The following kotlin code is the one I'm using which is actually equivalent to setSystemUiVisibility method in Java. playerView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)

android.view.View.systemUiVisibility deprecated. What is the replacement?

时光怂恿深爱的人放手 提交于 2020-07-03 09:38:07
问题 I have updated the project target API version to 30, and now I see that the systemUiVisibility property is deprecated. The following kotlin code is the one I'm using which is actually equivalent to setSystemUiVisibility method in Java. playerView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)

For input string: “Mat [ 0*0*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x78a0dff700, dataAddr=0x0 ]” - Error filling matrix

醉酒当歌 提交于 2020-07-03 08:07:10
问题 I am working with opencv on android for the development of an image segmentation application, but with the watershed algorithm. I am opening an image and creating a mask with the same image size and passing 0 for all the rows and columns of that mask. However, in the next step, which is to go through an array of 0 and add as coordinates in that array, I have the error: java.lang.NumberFormatException: For input string: "Mat [0 * 0 * CV_32FC1, isCont = true, isSubmat = false, nativeObj =

How to create an immutable list in Kotlin that is also an immutable list in Java?

点点圈 提交于 2020-07-03 01:59:48
问题 I have a Java/Kotlin interop problem. A Kotlin immutable list is compiled into a normal java.util.ArrayList that is mutable! Kotlin (library): class A { val items: List<Item> = ArrayList() } Java (consumer): A a = new A(); a.getItems().add(new Item()); // Compiles and runs but I wish to fail or throw How to make my Kotlin class fully immutable from Java perspective too? 回答1: All non- Mutable____ collections in Kotlin are compile time read-only types by default, but not immutable . See the

How to create an immutable list in Kotlin that is also an immutable list in Java?

五迷三道 提交于 2020-07-03 01:59:32
问题 I have a Java/Kotlin interop problem. A Kotlin immutable list is compiled into a normal java.util.ArrayList that is mutable! Kotlin (library): class A { val items: List<Item> = ArrayList() } Java (consumer): A a = new A(); a.getItems().add(new Item()); // Compiles and runs but I wish to fail or throw How to make my Kotlin class fully immutable from Java perspective too? 回答1: All non- Mutable____ collections in Kotlin are compile time read-only types by default, but not immutable . See the