简体   繁体   中英

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)

I develop the selenium code that:

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.edge.EdgeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;
    import java.util.List;

    public class TestDemoQA {
        public static void main(String[] args) throws InterruptedException{
            System.setProperty("webdriver.edge.driver", "C:\\Users\\Suganthan\\Downloads\\MicrosoftWebDriver.exe");
            WebDriver driver = new EdgeDriver();
            driver.get("http://demoqa.com/");
            driver.manage().window().maximize();`

I'm getting the error that is:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)

I'm trying to solve this issue according to This Solution by upgrading guava-21.0. But I'm still getting this error. could anyone give a solution to solve it?

Finally, I found a solution for this. It's simple guys. Add latest guava jar in your project. Note: If you have already old one jar (Please remove that and add it new one). Follow the link: mvnrepository.com/artifact/com.google.guava/guava/29.0-jre

This error message...

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)

...implies that the JVM was unable to initiate/spawn your program.

As @GhostCat pointed your main issue is the incompatibility between the guava version and other binary versions you are using.

Solution

  • Upgrade JDK to recent levels JDK 8u181 .
  • Upgrade Selenium to current levels Version 3.14.0 .
  • When you remove the previous version of Selenium Client ensure that all the associated jars are properly removed.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Execute your @Test .

Note that you remove the old guava you have from the jar lists and only then replace with the new one

I kinda figured out what this is. So I was using TestNG added to my classpath of the project.

When I traditionally kept Selenium Jars like given below, it threw the error as stated in the question.

Selenium Jars

Now, if you are getting the error even after updating your selenium jars to latest version, then it is matter of concern inside your TestNG jars. If you navigate to testng jars folder closely, you would see that guava is already present there (with some obsolete version in most cases). Just delete that.

In my case, I had latest guava jar in my selenium jars folder (version 30 or something), but In my TestNG folder, I had guava jar of some 19 version -- thereby creating a confusion for jvm.

So in short, in such scenarios where updated jars are downloaded but still you get this kind of an error, it would be mostly a case of some sort of ambiguity.

This issue happened because guava lib version is different in Hive lib folder and Hadoop shared folder.

To fix this, we need to ensure the versions are consistent. Fix the issue

Follow these steps to fix it:

--> Go to $HIVE_HOME (%HIVE_HOME%)/lib folder and find out the version of guava. For Hive 3.0.0, it is guava-19.0.jar.

--> Go to $HADOOP_HOME (%HADOOP_HOME%)/share/hadoop/common/lib folder and find out the version of guava. For Hadoop 3.2.1, the version is guava-27.0-jre.jar.

-->If they are not same (which is true for this case), delete the older version and copy the newer version in both. In this case, delete guava-19.0.jar in Hive lib folder, and then copy guava-27.0-jre.jar from Hadoop folder to Hive.

Issue resolved!

If your Hive and Hadoop versions are not consistent, you may encounter other similar strange errors like this. The common approach to fix them is to make sure JAR file versions are the same. Typically if you align Hadoop and Hive versions, these issues wouldn't happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM