-1

I'm using HTMLUnit in my Java application.

This code:

 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();
            }

wokrs fine in console app.

But when I try to use it in 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();

        }
    });


}

}

It returns me this error: http://pastebin.com/YV7QcaWM

Could You help me, please? :)

Robin Green
  • 29,408
  • 13
  • 94
  • 178
PoQ
  • 184
  • 2
  • 13
  • Put (short) code as an [edit to the question](http://stackoverflow.com/posts/20301396/edit). Few people will follow external links, and the links 'go stale'. – Andrew Thompson Nov 30 '13 at 14:31
  • possible duplicate of http://stackoverflow.com/questions/17556397/htmlunit-and-java-nosuchmethodexception-createdefaultsslcontext – Robin Green Nov 30 '13 at 14:55

2 Answers2

1

A reflective method call is failing. This probably means you have an incompatible version of the jar containing the class org.apache.http.conn.ssl.SSLSocketFactory on your CLASSPATH.

In the past, I have occassionally found JBoss Tattletale to be useful in finding problematic jars on my CLASSPATH.

Robin Green
  • 29,408
  • 13
  • 94
  • 178
0

OK, I think I've found the solution: I've just threw my HTMLUnit code to other (new) class constructor and call this class in actionPerformed method. It works fine now.

PoQ
  • 184
  • 2
  • 13