小编tak*_*rkk的帖子

断言上“类型不匹配:无法从 void 转换为 boolean”

代码如下:

import static org.testng.Assert.assertEquals;

import static org.testng.Assert.assertTrue;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ContactPageElements {
    public static WebElement element = null;
    public static String baseURL1 = "http://something.com";

    //Clicking logo should take you back to the baseURL
    public static void clickLogo (WebDriver driver) {
        element = driver.findElement(By.xpath(".//*[@id='blah'"));
        element.click();
        String currentURL = driver.getCurrentUrl();
        assert.assertEquals(currentURL, baseURL1);
    }
}
Run Code Online (Sandbox Code Playgroud)

对于断言,我收到错误:“类型不匹配:无法从 void 转换为布尔值”

java testng selenium assert

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

为什么这段代码不起作用?错误

System.out.print( "Enter an int > " );
int i = scan.nextInt();
while ( i != -1 ) {
    System.out.println( "Hello" );
    System.out.print( "Enter an int > " );
    i = scan.nextInt();
}
Run Code Online (Sandbox Code Playgroud)

假设用户输入3,5和-1,此代码的输出是多少?我已经尝试将其加载到多个编辑器并尝试它但它不断给我错误,如:

int i = scan.nextInt ( );
        ^
symbol:   variable scan
Run Code Online (Sandbox Code Playgroud)

java

-3
推荐指数
1
解决办法
51
查看次数

随机数组错误

为什么程序显示java.lang.ArrayIndexOutOfBoundsException:11?该程序需要打印11个数字.9个数字应该是随机的.它打印11个数字但有错误.

public class Main {
    public static void main(String[] args) {
        Random random  = new Random();
        int[] Cnum = new int[11];
        Cnum[0]=0;
        Cnum[1]=9;
        System.out.print(Cnum[0]);
        System.out.print(Cnum[1]);

        for(int a = 2; 2 < 10; a++){
            Cnum[a]=random.nextInt(9);
            System.out.print(Cnum[a]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出应该是(x是随机的):

09xxxxxxxxx 
Run Code Online (Sandbox Code Playgroud)

但它的输出是:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
    at CellphoneNumberGenerator.Main.main(Main.java:17)
    09505423220
Run Code Online (Sandbox Code Playgroud)

java

-5
推荐指数
1
解决办法
54
查看次数

初学者......我不知道我在Arraylist上的添加有什么问题

它一直在说no suitable method found for add.

public class MovieLibrary {

    private ArrayList<Movie> movies; 

    public MovieLibrary() {
        movies = new ArrayList<Movie>();
    }

    public void addMovie(String title, int year) {
        movies.add(title);
        movies.add(year);
    }
} 
Run Code Online (Sandbox Code Playgroud)

java

-5
推荐指数
1
解决办法
106
查看次数

什么是^ =运算符?

我刚刚在SO上找到了答案,其中一个代码示例(我认为是java)使用了一个我以前从未见过的运算符:^=.我搜索谷歌和SO并且无法在其他任何地方找到它,当我尝试使用java测试时,eclipse发疯了.也许这只是答案中的一个错字,我不确定.这个运营商是什么?它有名字吗?它的用语是什么?

java operators bitwise-operators

-18
推荐指数
2
解决办法
1418
查看次数

标签 统计

java ×5

assert ×1

bitwise-operators ×1

operators ×1

selenium ×1

testng ×1