How to solve Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE? - java

I'm trying to upload a file using Selenium web driver. Above error receive. I know code is ok. Most of post saying it is because "dependencies". How can I solve it? I checked there was no same name jar files. Here I have show some screen shot of my jar files. How can I solve this dependencies problem?
Java code:
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class FusekiStart {
public static void main(String[] args) {
/* Selenium config */
String PROXY = "localhost:3030";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
driver.get("http://localhost:3030/control-panel.tpl");
driver.findElement(By.xpath("//input[#value='Select']")).click();
driver.findElement(By.xpath("//input[#type='file']")).sendKeys("C:\\Users\\user1\\Desktop\\Ontology.owl");
driver.findElement(By.xpath("//input[#value='Upload']")).click();
}
}
Error message:
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:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:68)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:55)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:93)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
at uom.brts.statisticalmt.FusekiStart.main(FusekiStart.java:39)

Check this link:
Source Code at Grep
You are missing BasicLineFormatter class from org.apache.http.message package.

I would say not this will fix your problem but can you see by including a httpcore 4.2.2 jar file is what your are using currently. Can you try to get the higher one from the Link and replace it with current httpcore 4.2.2 and see what difference it makes ?

I faced the same problem. After a lot of debugging, I found out that there is a CLASSPATH conflict. A jar file already existing in the project
httpclient-osgi-4.2.1.jar
was conflicting with selenium jar files. Fortunately for me, the httpclient-osgi-4.2.1.jar file is not required in the project anymore, so I could safely remove it. After that the problem is gone.
The error message is pathetic. It doesn't help in any way to point out the real problem.

Related

Updated Katalon Studio to version 5.9.1 - ClassNotFoundException

After updating Katalon Studio to 5.9.1, we occasionally get java.lang.ClassNotFoundException: cz.elektLabs.Keywords on our custom keyword class while running tests in Jenkins.
What is weird is that it doesn't happen every time and we are not able to reproduce it. It worked before in 5.7.
Here is beginning of our custom keyword class:
package cz.elektLabs
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import org.openqa.selenium.By
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import groovy.json.JsonSlurper
import groovy.time.TimeCategory
import internal.GlobalVariable
class Keywords {
#Keyword
def boolean checkIfValidImage(String url) {
...
}
...
}
And here is the error we get:
2018-12-14 09:18:53.987 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ? cz.elektLabs.Keywords
2018-12-14 09:18:53.988 ERROR c.k.katalon.core.main.TestCaseExecutor - ? cz.elektLabs.Keywords.openAndLogin() FAILED.
Reason:
java.lang.ClassNotFoundException: cz.elektLabs.Keywords
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.getCustomKeywordClassAndSetMetaClass(CustomKeywordDelegatingMetaClass.java:98)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:44)
at TestSystem.run(TestSystem:17)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:321)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:129)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:112)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:81)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:149)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1544775530390.run(TempTestSuite1544775530390.groovy:36)
Is there anything we could do to fix this issue?
edit: We updated Katalon Studio to version 5.10.1 and we are still getting ClassNotFoundException or NoClassDefFoundError every now and then.
Please make sure you have installed Open JDK 1.8 on the machine.

org.testng.TestNGException: Cannot instantiate class

I am receiving the following errors when I am trying to run my script
org.testng.TestNGException: Cannot instantiate class Caused by:
java.lang.reflect.InvocationTargetException Caused by:
java.lang.IllegalStateException: The path to the driver executable
must be set by the webdriver.ie.driver system property;
package EDRTermsPackge;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
public class ContactInformationTesting {
//For use of IE only; Please enable for IE Browser
WebDriver driver = new InternetExplorerDriver();
#BeforeMethod
public void beforeMethod() {
//Using or Launching Internet Explorer
String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe";
//For use of IE only; Please enable for IE Browser
System.setProperty("webdriver.ie.driver", exePath);
}
#Test
public void OpenPage_Login() {
driver.get("http://cp-qa.harriscomputer.com/");
}
}
You should set your path to driver first and then instantiate IEDriver, you can't use new InternetExplorerDriver(); before System.setProperty("webdriver.ie.driver", exePath);
In your case you could do something like this (No need for #BeforeMethod to do just this simple property setup):
public class ContactInformationTesting {
//Using or Launching Internet Explorer
String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe";
//For use of IE only; Please enable for IE Browser
System.setProperty("webdriver.ie.driver", exePath);
//For use of IE only; Please enable for IE Browser
WebDriver driver = new InternetExplorerDriver();
#Test
public void OpenPage_Login() {
driver.get("http://cp-qa.harriscomputer.com/");
}
String exePath = "\Users\jj85274\Desktop\IEDriverServer.exe";
This line kind of hints as if you are trying to set the IEDriverServer binary from a network drive. Is that so ? I am not sure if network paths can be accessed by Java code directly.
I would suggest that instead of trying to add the IEDriverServer.exe path in your source code for every test, you might as well include this binary in your PATH variable. You can do this on windows by dropping this exe into one of the directories that is listed in the output of the below command
On Windows
echo %PATH%
On Non-Windows
echo $PATH

UnsatisfiedLinkError when calling new World()

My error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:130)
Caused by: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D
at org.jbox2d.common.Timer.now(Native Method)
at org.jbox2d.common.Timer.reset(Timer.java:35)
at org.jbox2d.common.Timer.<init>(Timer.java:31)
at org.jbox2d.dynamics.World.<init>(World.java:587)
at org.jbox2d.dynamics.World.<init>(World.java:158)
at org.jbox2d.dynamics.World.<init>(World.java:154)
at org.jbox2d.dynamics.World.<init>(World.java:145)
at com.badlogic.gdx.physics.box2d.World.<init>(World.java:61)
at com.example.blockbunny.states.Play.<init>(Play.java:22)
at com.example.blockbunny.handlers.GameStateManager.getState(GameStateManager.java:36)
at com.example.blockbunny.handlers.GameStateManager.pushState(GameStateManager.java:46)
at com.example.blockbunny.handlers.GameStateManager.<init>(GameStateManager.java:20)
at com.example.blockbunny.main.Game.create(Game.java:33)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:146)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)
And this occurs when I do this:
world = new World(new Vector2(0, -9.81f), true);
I have looked online, and some solutions included using this:
import com.badlogic.gdx.utils.GdxNativesLoader;
GdxNativesLoader.load();
However, I don't know where to put this function, and if it even works (I tried putting it in several different places)
How can I fix this issue?
Help will be appreciated, thanks!
As requested, here are my imports:
import static com.example.blockbunny.handlers.B2DVars.PPM;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.example.blockbunny.handlers.GameStateManager;
import com.example.blockbunny.main.Game;
I used Box2d several time with libgdx and i never encountered such a problem :
here what i propose t you :
GdxNativesLoader.load();
should be put on the create() method, but that doesn't seem to work with you
also try call it in a static way like this :
static {
GdxNativesLoader.load();
}
but i thin your problem is the extension of the library that you are using
verify that you are using gdx-box2d and not gdx-box2d-gwt which is used only for Html project
Verify that you are using the right (jar file) /(extension library) : gdx-box2d.jar and gdx-box2d-natives.jar (also verify the build path)
also try :
upgrade the box2d version that you're using
those were all the arrows i had ! hope one of it will work
Good luck !!
I came across the same issue, was using the gwt libraries. Updated the Maven dependency artifact from
gdx-box2d-gwt
to
gdx-box2d
and it fixed the error.

NoClassDefFoundError error while using Selenium with java

I am new to Selenium and I am trying to access google.co.in. My code is
public static void main(String[] args) {
String baseUrl = "https://www.google.co.in/";
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
}
But I am getting an error which says Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
and I have also written two import statements after loading the appropriate jar file
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
I am new to both selenium and java..So please help..
You must add this library:
selenium-server-standalone-version.jar
and
selenium-java-version.jar
download here: Selenium Downloads

Eclipse / Selenium unable to locate correct library for verifyText, isElementPresent etc

I am new to Eclipse and trying to run a simple selenium test.
However, I get the error message when I mouse over certain elements such as assertTrue with:
"void junit.framework.Assert.assterTrue(boolean condition)
Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source."
I have added all the following referenced libraries (including the path details of their location on my PC):
selenium-java-2.0rc3.jar
selenium-java-2.0rc3-srs.jar
selenium-server-standalone-2.0rc3.jar
selenium-java-2.0b3.jar
selenium-java-2.0b3-srs.jar
Plus some junit files (4.7).
I have managed to fix similar problems with verifyText by opening the declaration and then trying to associate each selenium jar in turn until Eclipse recognises it. However, none of them seem to work with assertTrue. Does anyone have any idea which other Selenium downloads I should use if I need to do something else?
==================================================================================
Edit: I found the answer. I needed to link AssertTrue with one of the junit files instead!
==================================================================================
Paste of code below:
package com.eviltester.selenium2;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class MySecondSeleniumTest extends SeleneseTestCase {
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.co.uk/");
selenium.start();
}
#SuppressWarnings({ "deprecation", "deprecation" })
#Test
public void testSel1() throws Exception {
Selenium selenium2 = selenium;
selenium2.open("/search?source=ig&hl=en&rlz=&q=thetechnicalauthor+blog&aq=f&aqi=&aql=&oq=");
selenium2.click("link=The Technical Author: How to put keywords into your blog");
selenium2.waitForPageToLoad("30000");
*assertTrue*(selenium2.isElementPresent("//div[#class='mm']"));
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
The error "This element has no attached Javadoc and the Javadoc could not be found in the attached source" indicates that the classpath for JDK is not set.
To find the exact path where java is installed give the below command:
which java
OUTPUT: /usr/bin/java Then set the path for JDK using the below commands:
export PATH=$PATH:/usr/bin/java
export JAVA_HOME=/usr/bin/java
To check whether the java path is set correctly give the below command:
java -version

Categories