NoSuchFieldError: INSTANCE error while running Phantomjs

455 views
Skip to first unread message

jh

unread,
Jan 24, 2016, 10:38:23 PM1/24/16
to Selenium Users
I'm trying to run phantomjs in the main class, but I kept getting this error of java.lang.NoSuchFieldError: INSTANCE when the location of the phantomjs.exe is in the correct path. What could the problem be and how can I solve it?

Code 

      String p = System.getProperty("user.dir");
        String imPath = p + "\\ImageMagick-6.9.3-1-portable-Q16-x64";
               
        ProcessStarter.setGlobalSearchPath(imPath);
       
        // create command
        ConvertCmd cmd = new ConvertCmd();       
        cmd.setSearchPath(imPath);
       
        String url = "https://www.twitter.com/";
               
        // Start the headless browser
        DesiredCapabilities dc = new DesiredCapabilities();
        ((DesiredCapabilities) dc).setJavascriptEnabled(true);
        ((DesiredCapabilities) dc).setCapability("takesScreenshot", true);
        ((DesiredCapabilities) dc).setCapability(
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                p + "\\driver\\phantomjs.exe"
        );
        WebDriver driver = new PhantomJSDriver(dc);
          


Error
run:
Jan 25, 2016 11:04:48 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Users\janice\Documents\NetBeansProjects\Project\driver\phantomjs.exe
Jan 25, 2016 11:04:48 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 34102
Jan 25, 2016 11:04:48 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=34102, --webdriver-logfile=C:\Users\janice\Documents\NetBeansProjects\Project\phantomjsdriver.log]
Jan 25, 2016 11:04:48 AM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:82)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:95)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:104)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:62)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:572)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:174)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:158)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:125)
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:74)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:251)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:228)
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:89)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:63)
    at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.<init>(PhantomJSCommandExecutor.java:62)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:115)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:104)
    at gov.spf.project.update.Im4Test.main(Im4Test.java:49)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Krishnan Mahadevan

unread,
Jan 24, 2016, 10:50:21 PM1/24/16
to Selenium Users
Janice,

The problem is due to a messed up CLASSPATH.


Something in your CLASSPATH is basically causing this mess up

See if adding the following helps you [ am assuming that you are using Maven ]

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.1</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.4.1</version>
</dependency>

You can get more context around a similar problem by going through this thread : http://stackoverflow.com/questions/21864521/java-lang-nosuchfielderror-org-apache-http-message-basiclineformatter-instance [Its not the exact same context, but it should give you a lot of ideas on how to go about deciphering this on your own ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4ed8e09b-abd4-423b-9229-c154bf5eb77a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jh

unread,
Jan 24, 2016, 11:05:30 PM1/24/16
to Selenium Users
Hi Krishnan,

Thank you for your reply. However, I am not using maven in this case. May I know what do you exactly mean by a messed up classpath?

Janice

Krishnan Mahadevan

unread,
Jan 24, 2016, 11:08:20 PM1/24/16
to Selenium Users
So what are you using to have your Java code resolve classes ?
Are you using any build tool such as Gradle/ANT/[Maven you said you arent ]

Or are you just adding classes to your classpath through your IDE and then working with them ?
If yes, then I would suggest that you please get yourself oriented with a build tool such as Maven and then use it.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages