NoClassDefFoundError in Java: com/google/common/ba

2019-01-02 23:47发布

When I executing the following code:

public static void main(String[] args) {
    try {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http:www.yahoo.com");
    } catch (NoClassDefFoundError ex) {
        System.out.println("error: " + ex.getStackTrace());
    }
}

I'm facing the following error:

error:[Ljava.lang.StackTraceElement;@80f4cb

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function


Could someone help me to find the solution or reason for this?

15条回答
做自己的国王
2楼-- · 2019-01-03 00:24

I had the same problem, and finally I found that I forgot to add the selenium-server-standalone-version.jar. I had only added the client jar, selenium-java-version.jar.

查看更多
欢心
3楼-- · 2019-01-03 00:26

I encountered the same error and after the investigation, I found that library selenium-api 2.41.0 requires guava 15.0 but it was overridden by an older version so I declared guava 15.0 as a direct dependency by adding following configuration in pom.xml:

<dependency>
        <artifactId>guava</artifactId>
        <groupId>com.google.guava</groupId>
        <type>jar</type>
        <version>15.0</version>
</dependency>
查看更多
不美不萌又怎样
4楼-- · 2019-01-03 00:26

I got the same error, but it was resolved if you add the libraries of selenium (again if you haven't), if you are using INTELIJ

project>projectStructure>Module>+>add the selenium jars (both from lib folder and outside ones.).

Same needs to be done for other IDE's as well, like eclipse.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-03 00:27
this is for chrome  
System.setProperty("webdriver.chrome.driver","D:\\Testing_offical\\chromedriver.exe");
driver =new ChromeDriver();
this is for fire fox 
System.setProperty("webdriver.gecko.driver",""D:\\Testing_offical\\geckodriver.exe"");
driver =new FirefoxDriver();

pattern :

System.setProperty("webdriver.gecko.driver","**Path of the gecko driver** ");

Note download gecko from here :- http://docs.seleniumhq.org/download/

查看更多
淡お忘
6楼-- · 2019-01-03 00:28

It looks like you're trying to import some google code:

import com.google.common.base.Function;

And it's not finding it the class Function. Check to make sure all the required libraries are in your build path, and that you typed the package correctly.

查看更多
Explosion°爆炸
7楼-- · 2019-01-03 00:29

I had the same issue. I found that I forgot to add selenium-2.53.0/selenium-java-2.53.0-srcs.jar file to my project's Reference library.

查看更多
登录 后发表回答