我有一个运行得很好的函数。但我对Kotlin还不熟悉,所以我想要一种更像Kotlin的方式。我的算法是非常标准的。所以我的问题是:有没有一种方法可以只用Kotlin已知函数得到同样的结果,或者更像Kotlin的方法?
fun sumOfdivider(numerToCalculate: Int) : MutableList<Int>{
var CalculationNumer = numerToCalculate
val numberList = ArrayList<Int>()
var helpCounter = 1
while (Calculati
我需要在Kotlin中执行一个for循环: for (setNum in 1..(savedExercisesMap[exerciseKey] as HashMap<*, *>)["sets"] as Int){ 但是我得到了这个错误: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer 我不认为这会是一个问题。有没有发生这种情况的原因以及如何修复?
我试图在java中将字符串"3.0“转换为int。我试图使用Integer.parseInt进行转换,但它引发了一个异常。知道如何将带有十进制值的字符串在java和kotlin中转换为int。
String value = "3.0";
int i = Integer.parseInt(value);
我有这样的功能,将字符串语句转换为列表词。我在Java中创建了这个函数,并在Android中使用默认的Kotlin转换转换为Kotlin,但是我相信在Awesome中可以有很多方法来缩短这段代码。如果你能分享你的代码并帮助我(和所有人)提高我们在Kotlin的知识,我会很好。
private fun stringToWords(mnemonic: String): List<String> {
val words = ArrayList<String>()
for (word in mnemonic.trim { it <= ' '
Java、Kotlin和Android如何处理在递增索引值的同时返回给定索引处的Array值?
int[] someArray = new int[5];
int index = 0;
int result;
result = someArray[index++];
哪个索引将传递给结果?它是先递增index,然后将其传递给someArray[1],还是将index的原始值传递给someArray[0],然后递增index
我正在尝试在我的项目中使用来自android库的新ViewModel。
我在github上学习了很多样本项目。最后,我想在我的项目上实现这个架构,但我无法构建它。
分级控制台:
....AppComponent.java:6: error: [dagger.android.AndroidInjector.inject(T)] kibar.app.ui.fragment.HomeFragmentViewModel cannot be provided without an @Inject constructor or from an @Provides-annotated method.
e:
作为标题,我有代码:
val description= mutableMapOf(
"father2" to "123",
"father" to mutableMapOf<String,String>())
description["father"]["child"] = "child value"
如果我尝试这个:description["father"]["child"]="child value"
我会得到错误:
U
我在Kotlin中创建了一个数据类,其中包含了一个ByteArray图像。当我构建时,我有以下错误:
Error:Kotlin: [Internal Error] java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Cause: An operation is not implemented: primitive arrays are not supported yet
File being compiled at position: file:///my/home/
我尝试使用@JvmOverloads为Kotlin函数创建重载方法。出于好奇,我尝试查看字节码并反编译Java代码。但是,我无法理解Java代码。
下面是一个简单的Kotlin代码
class MyClass {
@JvmOverloads
fun doSomething(a : Int = 200, b : Int = 300){
}
}
以下是反编译后的java代码:
public final class MyClass {
@JvmOverloads
public final void doSomething(int
Android Studio 2.3.3,Java 8,Kotlin 1.1.3-2
项目的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
dependencies {
classpath
我想在Kotlin中创建一个具有特定数量元素的对象数组,问题是我现在不知道声明中每个对象的当前初始化值,我尝试了:
var miArreglo = Array<Medico>(20, {null})
在Java中,我有这个,这正是我想要的,但在Kotlin中我需要它。:
Medico[] medicos = new Medico[20];
for(int i = 0 ; i < medicos.length; i++){
medicos[i] = new Medico();
}
上面的Java代码的Kotlink等价物是什么?
此外,我还尝试了:
var misD
我正在尝试使用共享首选项将数据发送给另一个人,当我发送该值时,会得到如下所示的异常 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.medicaltimetableapp, PID: 27357
java.lang.IllegalStateException: Property s_year should be initialized before get.
at kotlin.properties.NotNullVar.getValue(Delegates.kt:62)
at com.example.
描述了我希望安装的带有^2.3.5版本的定位包的bug,但是我在设备上得到了这样的消息错误:
java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.v
在学习kotlin时,我尝试为图像转换创建makeSceneTransitionAnimation,但它不像在java中那样工作,这是适配器类中的代码
itemView.imageContent.setOnClickListener {
val i = Intent(context, ImagePreviewActivity::class.java)
i.putExtra("IMAGE", item.content)
val trans = context.getString(R.string.transition)
val options =