小编Sim*_*one的帖子

为什么使用绑定类的视图引用被标记为@Nullable?

我有一个带有一些 TextView 和 CardView 的布局。只有引用 binding.mycardview 返回一个对象CardView?,但根据文档

空安全:由于视图绑定创建对视图的直接引用,因此不存在因视图 ID 无效而导致空指针异常的风险。此外,当视图仅出现在布局的某些配置中时,绑定类中包含其引用的字段将标记为 @Nullable。

我的布局 row.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:id="@+id/cVComune"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/space"
        android:layout_marginTop="@dimen/space"
        android:layout_marginEnd="@dimen/space"
        android:layout_marginBottom="@dimen/space"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/tvComune"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/space"
                android:layout_marginTop="@dimen/space"
                android:textSize="@dimen/text_label_medium"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/tvCap"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/space"
                android:layout_marginTop="@dimen/space"
                android:textSize="@dimen/text_label_medium"
                app:layout_constraintStart_toEndOf="@+id/ivMail"
                app:layout_constraintTop_toBottomOf="@+id/tvComune" />

            <TextView
                android:id="@+id/tvPrefisso"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/space"
                android:layout_marginTop="@dimen/space"
                android:textSize="@dimen/text_label_medium"
                app:layout_constraintStart_toEndOf="@+id/ivPhone"
                app:layout_constraintTop_toBottomOf="@+id/tvComune" />

            <TextView
                android:id="@+id/tvAbitanti"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/space"
                android:layout_marginTop="@dimen/space"
                android:textSize="@dimen/text_label_medium"
                app:layout_constraintStart_toEndOf="@+id/ivAbitanti"
                app:layout_constraintTop_toBottomOf="@+id/tvComune" …
Run Code Online (Sandbox Code Playgroud)

xml android kotlin-null-safety android-viewbinding

8
推荐指数
1
解决办法
1337
查看次数

java.lang.NoSuchMethodError:使用 ChromeDriver 和 Selenium 的“java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()”

我正在研究 Selenium,我有这个测试方法:

@Test
public void testHeight() {
    System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
    
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.rapidtables.com/convert/length/feet-to-cm.html");
    
    driver.findElement(By.xpath("//*[@id=\"x\"]")).sendKeys("6");
    driver.findElement(By.xpath("//*[@id=\"calc\"]")).click();
    
    WebElement txtBoxContent = driver.findElement(By.xpath("//*[@id=\"doc\"]/form/table/tbody/tr[3]/td[2]/input"));
    
    String result = txtBoxContent.getAttribute("value");
    
    driver.close();
    
    System.out.println("The value is: " + result);
    
    assertEquals((double)180,Double.valueOf(result), 5);
    
}
Run Code Online (Sandbox Code Playgroud)

当我尝试在我的项目中使用 Junit 运行 Selenium 时,我收到此错误。奇怪的是,我尝试在一个只有该方法的新项目中运行该方法,并且一切正常。我没有忘记任何事情,Drivers/chromedriver.exe 包含在我的项目中,所有 Selenium 驱动程序都添加在类路径中。

java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()'
    at org.openqa.selenium.chrome.ChromeOptions.asMap(ChromeOptions.java:292)
    at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:94)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at test.selenium.TestAttractionViewSortByDistance.testHeight(TestAttractionViewSortByDistance.java:18)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at …
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver guava selenium-webdriver

5
推荐指数
1
解决办法
2万
查看次数

不适当的阻塞方法调用,但挂起函数“withContext”只能从协程或另一个挂起函数调用

在我的服务中,我需要调用onStartCommand一些需要的方法,withContext(Dispatchers.IO)例如CoroutineScope(Dispatchers.IO)

  • url = URL(pokemon.linkImage)
  • url.openConnection().getInputStream()
  • fOut= FileOutputStream(文件)
  • fOut.flush()
  • fOut.close()

Suspend function 'withContext' should be called only from a coroutine or another suspend function。所以 ifonStartCommand不能是一个挂起函数,因为它具有重写,并且由于方法withContext而不能被 CoroutineScope 调用Inappropriate blocking method call

val url = URL(pokemon.linkImage)
val iS = url.openConnection().getInputStream()
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

我的onStartCommand()

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {

    //create the directory on internal storage that will contains all pokemon images
    val path = applicationContext.filesDir.absolutePath …
Run Code Online (Sandbox Code Playgroud)

android android-context kotlin kotlin-coroutines

4
推荐指数
1
解决办法
3924
查看次数