I am trying to establish a connection between a Java-based project and a MySQL database. From what I can tell, the database seems to be fine (the expected information is stored in its columns). However, when I use the Java program to open a connection I obtain a StackOverflow error, which I am not sure why is happening:
Exception in thread "Thread-2" java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
I have taken several actions to solve this issue but none of them have worked. Among them, I have successfully run the example that is described in MySQLJavaTutorials, which makes me think that this issue is not because of either the JDBC connector, the operating system, the database itself or the MySQL server version.
However, I have noticed that if I completely delete the database (by executing DROP DATABASE mydatabase) I get the exact same exception, as if the database had never existed in the first place. This also happens if I alter the name of the database to one that does not exist on purpose. My machine uses:
Operating System: Ubuntu 64 bits 14.04.5 LTS
MySQL server version: 5.5.58
Eclipse Oxygen 2
Java 1.8.0_151
Do you have any idea of why this is happening?
While the project I am working on is rather complex, the location of the call where I invoke the function is:
#Override
public void openDBConnection() throws Exception {
//this method establish a database connection
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName(driver);
// Setup the connection with the DB
//////////////////////////////////////////////////////////////////////////////
String connection = "jdbc:mysql://" + host + "/" + dbname + "?"
+ "user=" + user + "&password=" + passwd + "&useSSL=false";
System.out.println(connection);
connect = DriverManager.getConnection(connection);
//////////////////////////////////////////////////////////////////////////////
} catch (ClassNotFoundException | SQLException e) {
throw e;
} finally {
}
}
The exception is thrown at the connect = DriverManager.getConnection(connection); line. The connection string that I obtain is fine. Actually, I am quite sure that this is not related to the JDBC connection because if I miswrite the driverĀ“s name then I get a reasonable error instead of it.
Related
I have created a client to connect to oracle fusion webservices. This was done for integration of oracle BI publisher via web services in oracle fusion by using JAXWS.
This integration is currently executing by a batch file from where we are calling the java utility and it is running fine.But as soon as I start executing the java utility from my oracle jdeveloper
(12.2.1.3.0), I get the below error.
I have already added jaxws-tools-2.1.4.jar & jaxws-rt-2.1.4.jar jars to my
Classpath & I have tried to find com.sun.xml.ws.api.client.ServiceCreationInterceptor class in jaxws-rt-2.1.4.jar but there is no such class exist.
Exception in thread "main" java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider **weblogic.wsee.jaxws.spi.WLSProvider could not be instantiated**
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at javax.xml.ws.spi.Provider.getProviderUsingServiceLoader(Provider.java:165)
at javax.xml.ws.spi.Provider.provider(Provider.java:125)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.oracle.xmlns.oxp.service.v2.ScheduleService_Service.<init>(ScheduleService_Service.java:46)
at com.oracle.xmlns.oxp.service.v2.ScheduleServiceClient.runReport(ScheduleServiceClient.java:40)
at interfaces.YBHRTaleoOLF.JobFullReport(YBHRTaleoOLF.java:49)
at interfaces.YBHRTaleoOLF.main(YBHRTaleoOLF.java:25)
**Caused by: java.lang.NoClassDefFoundError: com/sun/xml/ws/api/client/ServiceCreationInterceptor**
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at weblogic.wsee.jaxws.spi.WLSProvider.<clinit>(WLSProvider.java:132)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 9 more
**Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.api.client.ServiceCreationInterceptor**
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 28 more
Process exited with exit code 1.
I'm new to HtmlUnit. I tried a simple code for loading a web page using htmlunit and use the xpath to get to a specific div tag.
The xpath is correct. I have verified using the console.
The code that so far I tried is
import java.util.List;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class Test {
public static void main(String s[]) throws Exception
{
WebClient client = new WebClient();
HtmlPage page = client.getPage("http://jpu1.pv.sv.nextag.com/serv/iinedan/buyer/outPdir.jsp?search=camera");
List<?> items = page.getByXPath("//div[contains(#class,'search-result-cards')]//div[contains(#class,'listContainer')]");
for(HtmlElement item : (List<HtmlElement>)items)
{
List<?> imageContainer;
imageContainer = item.getByXPath("//div[contains(#class,'imageContainer')]/a");
System.out.println("Image container data length : "+imageContainer.size());
System.out.println("Image "+imageContainer.toString());
}
}
}
But when I execute this code, I'm facing the following exceptions.
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException:
org.w3c.dom.ElementTraversal
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 37 more
It seems to like its a configuration isssue. I downloaded the jar from the site and added it to my refrenced library. IDE that I'm using is eclipse. HtmlUnit version is htmlunit-2.13.jar
The org/w3c/dom/ElementTraversal present in library xml-apis-1.4.01.jar on which htmlunit depends on. So, as a solution you need to put this jar in your project's classpath.
However, htmlunit depends on number of libraries. And it could happen that, after you resolved the current error, you will get a noClassDefFoundError for some other class.
In order to resolve it easily, start using Maven.
Create a maven project.
Add an entry for htmlunit dependency in pom.xml as follows :
<dependencies>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.13</version>
</dependency>
</dependencies>
Now create a new class and add your code there.
Maven will ensure, all transitive dependencies of any library to be available and keep those in project classpath automatically (if in IDE).
Many jar package includes org.w3c.dom.ElementTraversal.
Such as xml-apis, batik-ext, jython.
I think jar package conflict maybe cause your problem.
Can you give more jar package version detail?
We are upgrading from junit-4.2 to junit-4.10. But with that, I am getting initializationError when launching firefox with below error stack. There is absolutely no reference to TestClassRunner (a class from junit-4.2) but not sure why we get it?
Type [unknown] not present
java.lang.TypeNotPresentException: Type [unknown] not present
at com.sun.proxy.$Proxy2.value(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
Caused by: java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3281)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3288)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3288)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3288)
at java.lang.Class.getAnnotation(Class.java:3229)
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Right click your project in Package Explorer > click Properties.
Go to Java Build Path > Libraries tab.
Click on 'Add Library' button.
Select JUnit.
Click Next.
OR
Run mvn clean compile test-compile
Tell me if it doesnt work, but it worked for me.
Well the issue was little difference. There were two classes of same name WebDriverRunner. The one that was getting loaded first (based on classpath entries) was incorrect (rather deprecated) one which had some reference of TestClassRunner class. After putting the other jar (with right WebDriverRunner) before the previous one resolved the issue. Thanks all for your suggestions.
I also faced this issue but not due to any code changes. In my case I was running a simple Robolectric test on the Android SDK 29 (as it was set in the TestConfiguration). I tried restarting Android Studio, cleaning the build and Invalidating cache but in the end this issue was resolved by changing the SDK to 28 in the Edit Configuration. I also don't have any solid reason to why this worked.
I am building a software in Java and JavaFX. It generates PDF reports (with DynamicReports) then uses SendGrid API to send to send them. I have already added the SendGrid API .jar file to the classpath.
The problem is that my JavaFX application crashes when I instanciate my subclass of SengGrid. As you can see:
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sendgrid/SendGrid$Email
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Reporting.TableReport.lambda$build$0(TableReport.java:160)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.sendgrid.SendGrid$Email
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more
Now the interesting part is that the API works perfectly when I call it from a non JavaFX project. And more interestingly, it also works when I call it from a "console" main class inside the very same JavaFX project.
So far, I have tried to call that "console" main from my JavaFX code as a sort of static method that would fulfill my task (sending the PDF files). But again, I encounter the very same exception.
Can anyone suggest a solution to solve this ? (or at least go around it)
Turns out it was an issue with Netbeans. Using the exact same code with Eclipse works perfectly. I couldn't find an explanation but I'm giving this answer for anyone who might stumble upon the same issue as me.
Can anyone tell me more about this error?
Exception in thread "main" java.lang.NoClassDefFoundError: org/rosuda/JRI/Rengine
at DataMining.RunMinerBack.checkRLibVersion(RunMinerBack.java:643)
at DataMining.RunMinerBack.init(RunMinerBack.java:831)
at DataMining.RunMinerBack.<init>(RunMinerBack.java:126)
at DataMining.ListMergeMembers.init(ListMergeMembers.java:1453)
at DataMining.ListMergeMembers.<init>(ListMergeMembers.java:95)
at DataMining.ListMergeMembers.main(ListMergeMembers.java:1585)
Caused by: java.lang.ClassNotFoundException: org.rosuda.JRI.Rengine
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
I have rJava installed, and I have JRI.jar in my CLASSPATH. I also checked and I do have Rengine.class in within JRI.jar, at the same path - org/rosuda/JRI/Rengine.class. I'm not sure what/where else to check, so any suggestions would be appreciated.