0

在我的代码中,尝试使用 getPage 方法时出错。我不确定问题是什么,也许我应该在哪里寻找任何想法?

我尝试将“找到”下的类添加到我的导入中,但它似乎不存在。这是我第一次发布 java 问题,如果需要更多信息,请告诉我。

错误: java:需要不兼容的类型:com.gargoylesoftware.htmlunit.html.HtmlPage 找到:com.gargoylesoftware.htmlunit.Page

我的代码

package com.buth.trabot;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.lang.Object;

import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import static org.junit.Assert.*;


/**
 * Created with IntelliJ IDEA.
 * User: Tyler
 * Date: 9/28/13
 * Time: 7:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    public static void main (String [] args) {
        final WebClient webClient = new WebClient();
        final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net");
        assertEquals("HtmlUnit - Welcome to HtmlUnit", startPage.getTitleText());
    }
}

我的 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>MavenFirst</groupId>
    <artifactId>MavenFirst</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>1.14</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
    </dependencies>
</project>
4

2 回答 2

0

我想你应该这样链接它:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.12</version>
</dependency>
于 2013-09-30T21:08:41.870 回答
0

getPage 的返回类型似乎是com.gargoylesoftware.htmlunit.Page. 你的变量是类型com.gargoylesoftware.htmlunit.html.HtmlPage

您需要更改变量的类型或添加演员表。

于 2013-09-30T10:28:58.930 回答