Tag: 安卓

Kotlin中的Android应用程序不能正确地扩大片段布局

我有个问题。 我写了一个Java Android应用程序并转换为Kotlin。 它在Java中工作正常,但现在当我运行应用程序,它给了我一个RuntimeError。 片段不能被夸大: 错误 FATAL EXCEPTION: main Process: com.jaielsoft.www.emergencyapp, PID: 10753 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jaielsoft.www.emergencyapp/de.htw_berlin.f4.ai.aa.activities.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class fragment … Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment …. Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter […]

Android Kotlin仪器测试不被识别为仪器测试

我正在尝试在我的Android项目中编写一个kotlin工具测试。 这一刻是非常基本的: class SimpleTest { @Test fun aTest() { Assert.assertTrue(true) } } 当我运行它时,它说no tests were found 。 但是当我运行这个类的Java版本时,系统会提示选择我要运行测试的设备(意思是AS将其识别为仪器测试)。 Java版本看起来像这样: public class AnyTest { @Test void aTest() { Assert.assertTrue(true); } } 如果我然后将这个Java类转换为Kotlin并重新运行测试,我得到相同的no tests were found 。 我在这里错过了什么? 谢谢

使用reflection读取Kotlin函数注释值?

给定一个像这样的接口方法(Android Retrofit),如何在运行时从Kotlin代码读取注解参数中指定的URL路径? ApiDefinition接口: @GET(“/api/somepath/objects/”) fun getObjects(…) 阅读注释值: val method = ApiDefinition::getObjects.javaMethod val verb = method!!.annotations[0].annotationClass.simpleName ?: “” // verb contains “GET” as expected // But how to get the path specified in the annotation? val path = method!!.annotations[0].???????? 更新1 感谢您的回答。 我还在苦苦挣扎,因为我看不到要使用什么types来执行以下操作: val apiMethod = ApiDefinition::getObjects ….然后将该函数引用传递到这样的方法(它被重用) private fun getHttpPathFromAnnotation(method: Method?) : String { val a […]

Android中的文字闪烁着最简洁的Kotlin

我需要使一些文本(目前在TextView )闪烁几秒钟。 关于如何在java中这样做有几个答案,但是因为Kotlin有一些java不支持的语法/语言特性,所以我在问什么是使用Kotlin在Android上使文本闪烁的最简洁的方法。 虽然我的目标是做一个平淡无奇的眨眼,但是我也接受这样的做法。 请注意,我也在考虑轻量级代码性能。 感谢您的回答!

在另一个模块的function模块中找不到Kotlin类

使用另一个function模块的com.android.feature插件在模块中找不到Kotlin类。 例如,在Android即时应用程序中,“基本”function中的Kotlin类不能从任何function模块引用。 Gradle版本:4.0-20170417000025 + 0000-全部 Android插件版本:3.0.0-alpha3 模块编译Sdk版本:25 模块构建工具版本:26.0.0 Android SDK工具版本:26.0.2 Kotlin版本:1.1.2-5

将源文件附加到kotlin库项目不会显示在AS中

我想把源代码附加到一个kotlin库项目,看起来我成功了,因为我现在有了源代码jar: https://jitpack.io/com/github/walleth/kethereum/bip44/0.21/ 之前的版本没有出口的来源 – 所以我认为这是成功的。 https://jitpack.io/com/github/walleth/kethereum/bip44/0.20/ 不幸的是,AS不显示来源。 我是这样产生的: allprojects { repositories { jcenter() maven { url ‘https://jitpack.io’ } } apply plugin: “kotlin” apply plugin: “jacoco” apply plugin: “maven” apply plugin: “com.github.ben-manes.versions” dependencies { compile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version” testCompile ‘org.assertj:assertj-core:3.8.0’ testCompile ‘junit:junit:4.12’ } task sourcesJar(type: Jar, dependsOn: classes) { classifier = ‘sources’ from sourceSets.main.allSource } task javadocJar(type: Jar, […]

在Kotlin使用Android获取和设置器

我是Kotlin的新手,在吸气剂和吸附剂方面工作。 我正在设置我的字符串值的一个数据类。 我有2个活动,从ActivityA我正在设置一个数据,我想要在其他ActivityB。 我如何从我的ActivityB中的数据类获取数据? 我的代码片段如下: 数据类HelperMethods: data class HelperMethods(val name: String, val publisher: String) ActivityA我正在设置数据: val userName = HelperMethods(“abc”,”efg”) 我想从我的ActivityB中的数据类中获取这些数据。

无法在kotlin`whenexpression式中使用string.contains()

我是新的kotlin,我已经尝试了几种使用下面的代码的方法 val strAction = “Grid” when(strAction){ strAction.contains(“Grid”)->println(“position is 1”) } 在上面的代码strAction.contains(“Grid”)这行显示了一个不兼容types的错误

在Android工作室Kotlin

我从kotlin使用,但是当我在我的项目中同步它,让我波纹管错误: Error:Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-3. Searched in the following locations: file:/D:/android-studio/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.2-3/kotlin-gradle-plugin-1.1.2-3.pom file:/D:/android-studio/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.2-3/kotlin-gradle-plugin-1.1.2-3.jar https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.2-3/kotlin-gradle-plugin-1.1.2-3.pom https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.2-3/kotlin-gradle-plugin-1.1.2-3.jar Required by: project : 这是我的build.gradle(Module) : apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ android { compileSdkVersion 25 buildToolsVersion “25.0.3” defaultConfig { applicationId “ir.baslam.kotlinme” minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName “1.0” testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt’), […]

匕首注射不适用于Kotlin的“物体”

花了大量的时间想弄清楚为什么我的匕首注射不起作用, 我意识到Kotlin中的“对象”types是个问题。 以下行不通,注入的“财产”是空的。 object SomeSingleton { @Inject lateinit var property: Property init { DaggerGraphController.inject(this) } } 但是,下面的DID工作得很好: class NotSingleton { @Inject lateinit var property: Property init { DaggerGraphController.inject(this) } } 我试过谷歌,我试过文件,但我不能指出背后的原因。 另外请注意,我还没有尝试过这与JAVA,JAVA没有反正建立单身人士的概念。 这是为什么? 为什么一个科特林单身人士无法注射成员,但一个非单身人士课程可以?