簡體   English   中英

找不到java.nio.file.Path的類文件

[英]class file for java.nio.file.Path not found

我正在使用org.assertj:assertj-core:3.6.2來測試我的android項目。 根據官方討論 ,我應該使用帶有assertj 3.x的java 8。

這是我的測試類,我正在嘗試驗證何時執行單擊代碼可以啟動預期的活動。

import android.content.Intent;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class LoginActivityTest {

    @Test
    public void testBtnLogin(){
        LoginActivity loginActivity = Robolectric.setupActivity(LoginActivity.class);

        loginActivity.findViewById(R.id.btnLogin)
                .performClick();

        Intent expectedIntent = new Intent(loginActivity,MainActivity.class);
        ShadowActivity shadowActivity = Shadows.shadowOf(loginActivity);
        Intent actualIntent = shadowActivity.getNextStartedActivity();
        Assertions.assertThat(actualIntent).isEqualTo(expectedIntent);
    }
}

但是當我運行測試時,我收到了這個錯誤:

:app:compileDebugUnitTestJavaWithJavac (Thread[Daemon worker,5,main]) started.
:app:compileDebugUnitTestJavaWithJavac
file or directory '/home/workspace/android/AndroidLib/app/src/testDebug/java', not found
Executing task ':app:compileDebugUnitTestJavaWithJavac' (up-to-date check took 0.006 secs) due to:
  Output file /home/workspace/android/AndroidLib/app/build/intermediates/classes/test/debug/com/cavalry/androidlib/sample/ui/activity/LoginActivityTest.class has been removed.
All input files are considered out-of-date for incremental task ':app:compileDebugUnitTestJavaWithJavac'.
Compiling with source level 1.7 and target level 1.7.
file or directory '/home/workspace/android/AndroidLib/app/src/testDebug/java', not found
Compiling with JDK Java compiler API.

/home/workspace/android/AndroidLib/app/src/test/java/com/cavalry/androidlib/sample/ui/activity/LoginActivityTest.java:43: error: cannot access Path
        Assertions.assertThat(actualIntent).isEqualTo(expectedIntent);
                  ^
  class file for java.nio.file.Path not found
1 error

:app:compileDebugUnitTestJavaWithJavac FAILED
:app:compileDebugUnitTestJavaWithJavac (Thread[Daemon worker,5,main]) completed. Took 0.556 secs.

我在谷歌搜索,發現它可能是由錯誤的java版本引起的(我真的不太確定)。

以下是有關我的java配置的一些信息:

$ java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

$ javac -version
javac 1.8.0_112


$ update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /home/java/jdk1.8.0_112/bin/java                 300       manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

在項目結構中,我將JDK設置為jdk1.8.0_112 在此輸入圖像描述

如果它是由java版本引起的,我該怎么辦? 如果沒有,那我該怎么辦?

ejohansson是對的,它可能不是超級可見,但org.assertj.core.api.Java6Assertionshttp://joel-costigliola.github.io/assertj/assertj-core.html中提到,我會試着去做將來更清楚( https://github.com/joel-costigliola/assertj/issues/63 )。

文檔已經更新,希望Android開發人員更容易找到正確的斷言入口點: http//joel-costigliola.github.io/assertj/assertj-core.html#android

使用Android Studio, 從自動導入中排除org.assertj.core.api.Assertions可能是一個好主意,因此在您忘記它之后將來不會發生這種情況:

  1. 暫時刪除靜態導入。
  2. 點擊F2導航到有問題的斷言。
  3. 按Alt + Enter顯示可用意圖操作列表。
  4. 突出顯示Assertions (org.assertj.core.api)的條目並點擊
  5. 在彈出的列表中選擇從自動導入中排除'org.assertj.core.api.Assertions'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM