我突然想通了这个宣言:
<uses-library
android:name="com.android.nfc_extras"
android:required="false"/>
Run Code Online (Sandbox Code Playgroud)
<application>
我的内部范围AndroidManifest.xml
使仪器测试失败:
java.lang.NoSuchMethodError: No static method allOf(Lorg/hamcrest/Matcher;Lorg/hamcrest/Matcher;)Lorg/hamcrest/Matcher; in class Lorg/hamcrest/core/AllOf; or its super classes (declaration of 'org.hamcrest.core.AllOf' appears in /system/framework/com.android.nfc_extras.jar)
at org.hamcrest.Matchers.allOf(Matchers.java:33)
at android.support.test.espresso.Espresso.<clinit>(Espresso.java:187)
at android.support.test.espresso.Espresso.onView(Espresso.java:75)
at com.example.abusik.espressotest.InstrumentedTest.changeText_sameActivity(InstrumentedTest.kt:34)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
Run Code Online (Sandbox Code Playgroud)
我现在想出的是:
我的InstrumentedTest.kt
档案:
package com.example.abusik.espressotest
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.*
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.withId
import …
Run Code Online (Sandbox Code Playgroud) 无法传递参数来Combiner().combine()
起作用.
Android Studio无法识别arg
扩展Foo
和实现Bar
.我究竟做错了什么?
abstract class Foo {
val f: Int = 1
}
interface Bar {
val b: String get() = "a"
}
class Combiner {
fun <T> combine(arg: T): Pair<Int, String> where T : Foo, T : Bar {
return arg.f to arg.b
}
}
class Program {
fun main() {
val list: List<Foo> = arrayListOf()
list.forEach {
if (it is Bar) {
Combiner().combine(it) //inferred type Any is not a subtype …
Run Code Online (Sandbox Code Playgroud)