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?
I met the same problem and fail even after installing the 'selenium-server-standalone-version.jar', I think you need to install the guava and guava-gwt jar (https://code.google.com/p/guava-libraries/) as well. I added all of these jar, and finally it worked in my PC. Hope it works for others meeting this issue.
you don't have the "google-collections" library on your classpath.
There are a number of ways to add libraries to your classpath, so please provide more info regarding how you are executing your program.
if from the command line, you can add libraries to the classpath via
java -classpath path/lib.jar ...
A
NoClassDefFoundError
is thrown when the JRE can't find a class. In your case, it can't find the classcom.google.common.base.Function
, which you most probably did not add to your classpath.EDIT
After downloading the following libraries:
and unzipping them and putting all JAR files in a folder called
lib
, the test class:ran without any problems.
You can compile and run the class as follows:
For me, in addition to selecting the jar - selenium-java-2.45.0.jar, I had to select all the jars in the "libs" folder under selenium root folder.
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.
Hope this helps.
When I caught the exception
java.lang.NoClassDefFoundError: com/google/common/base/Function
it was caused by errors in Project Libraries.Please check it in your project settings. For Intellij IDEA go to File - Project Structure and select Modules tab. All I needed to do to resolve this exception was re-adding the selenium library