-1

Java アプリケーションで HTMLUnit を使用しています。

このコード:

 final WebClient webClient = new WebClient(BrowserVersion.CHROME_16);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            webClient.getOptions().setJavaScriptEnabled(false);
            try {
                final HtmlPage page = webClient.getPage("http://ufs.pt/forum/forum.php"); 

                } catch (FailingHttpStatusCodeException e) {
            e.printStackTrace();
            } catch (MalformedURLException e) {
            e.printStackTrace();
            } catch (IOException e) {
            e.printStackTrace();
            }

コンソールアプリで問題なく動作します。

しかし、Window Builder で使用しようとすると、次のようになります。

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.swing.JFrame;
import javax.swing.JButton;

import junit.framework.Assert;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;


public class gui {

private JFrame frame;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                gui window = new gui();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public gui() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("New button");
    btnNewButton.setBounds(122, 60, 117, 25);
    frame.getContentPane().add(btnNewButton);

    btnNewButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            final WebClient webClient = new       WebClient(BrowserVersion.CHROME_16);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            webClient.getOptions().setJavaScriptEnabled(false);
            try {
                final HtmlPage page = webClient.getPage("http://ufs.pt/forum/forum.php");

            } catch (FailingHttpStatusCodeException e) {

                e.printStackTrace();
            } catch (MalformedURLException e) {

                e.printStackTrace();
            } catch (IOException e) {

                e.printStackTrace();
            }

            webClient.closeAllWindows();

        }
    });


}

}

このエラーが返されます: http://pastebin.com/YV7QcaWM

私を手伝ってくれますか?:)

4

2 に答える 2

1

リフレクティブ メソッドの呼び出しが失敗しています。org.apache.http.conn.ssl.SSLSocketFactoryこれはおそらく、CLASSPATHにクラスを含む互換性のないバージョンの jar があることを意味します。

過去に、JBoss Tattletale が CLASSPATH で問題のある jar を見つけるのに役立つことが時々ありました。

于 2013-11-30T14:54:41.440 に答える