Home > Enterprise >  Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Immut
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Immut

Time:04-11

Code trials:

package SeleniumSessions;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class TestChrome {

    public static void main(String[] args) {
       System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

        WebDriver driver=new ChromeDriver();

        driver.get("https://www.google.com");

    }
}

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.getExtraCommands(ChromeDriver.java:122)
    at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
    at SeleniumSessions.TestChrome.main

Error snapshot: enter image description here

CodePudding user response:

This error message...

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap

...implies that the file com/google/common/collect/ImmutableMap might be corrupted or there is some incompatibility between the version of the binaries you are using.


Further you need to take care of a couple of things as follows:

  • Instead of storing the chromedriver.exe binary right under C:\ try to put it within a directory as C:\\BrowserDrivers\\chromedriver.exe and change the System.setProperty() line accordingly. So effectively, the line of code will be:

    System.setProperty("webdriver.gecko.driver","C:\\BrowserDrivers\\chromedriver.exe");
    

Also ensure that:


Reference

You can find a relevant discussion in:

  • Related