Jackcess "NoClassDefFoundError" exception - java

I am using jackcess for the conncetivity to my access database. But I am following exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/CompareToBuilder
at com.healthmarketscience.jackcess.impl.RowIdImpl.compareTo(RowIdImpl.java:113)
at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1838)
at com.healthmarketscience.jackcess.impl.IndexData$Entry.compareTo(IndexData.java:1646)
at java.util.Collections.indexedBinarySearch(Collections.java:273)
at java.util.Collections.binarySearch(Collections.java:259)
at com.healthmarketscience.jackcess.impl.IndexData$DataPage.findEntry(IndexData.java:2368)
at com.healthmarketscience.jackcess.impl.IndexData.findEntryPosition(IndexData.java:722)
at com.healthmarketscience.jackcess.impl.IndexData.access$3300(IndexData.java:56)
at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.updatePosition(IndexData.java:2133)
at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2072)
at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.restorePosition(IndexData.java:2055)
at com.healthmarketscience.jackcess.impl.IndexData$EntryCursor.beforeEntry(IndexData.java:2017)
at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findPotentialRow(IndexCursorImpl.java:368)
at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntryImpl(IndexCursorImpl.java:262)
at com.healthmarketscience.jackcess.impl.IndexCursorImpl.findFirstRowByEntry(IndexCursorImpl.java:135)
at com.healthmarketscience.jackcess.impl.DatabaseImpl$DefaultTableFinder.findRow(DatabaseImpl.java:1890)
at com.healthmarketscience.jackcess.impl.DatabaseImpl$TableFinder.findObjectId(DatabaseImpl.java:1799)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.readSystemCatalog(DatabaseImpl.java:804)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:513)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:386)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:193)
at ass.Access.main(Access.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.builder.CompareToBuilder
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:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more
I have used jdbc but it is not working either. How can solve my problem?

Here's how I got Jackcess working, starting with a fresh install of NetBeans 7.4 on Windows 8:
I downloaded the latest Jackcess JAR file via the "Looking for the latest version?" link on files page. I saved it in the folder
C:\Users\Public\Java\
As listed on the Project Dependencies page for Jackcess, I downloaded the ZIPped binaries for the two required dependencies: commons-lang v2.x, and commons-logging v1.x. I unpacked the ZIP files into the above folder, so it now contained two sub-folders
C:\Users\Public\Java\commons-lang-2.6\
C:\Users\Public\Java\commons-logging-1.1.3\
I launched NetBeans and created a new Project (for a Java Application) named "myJackcessTest". I expanded the Project in the tree view, right-clicked "Libraries", chose "Add JAR/Folder...", and added the three JAR files:
Once that was done, I created my little test app...
package myjackcesstest;
import com.healthmarketscience.jackcess.*;
import java.io.File;
import java.io.IOException;
public class MyJackcessTest {
public static void main(String[] args) {
try {
Table table = DatabaseBuilder.open(new File("C:\\Users\\Public\\Database1.accdb")).getTable("Clients");
System.out.println(String.format("table contains %d row(s)", table.getRowCount()));
} catch (IOException e) {
e.printStackTrace();
}
}
}
...and when I hit F6 it ran fine:
run:
table contains 1 row(s)
BUILD SUCCESSFUL (total time: 0 seconds)

Jackcess has a dependency on Jakarta Commons Lang. You need to make sure that the commons lang and the other dependencies are on your classpath.

Related

MySQL Driver in Classpath, But Still: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [duplicate]

This question already has answers here:
Connect Java to a MySQL database
(14 answers)
Closed 7 years ago.
I have the following code:
import java.io.IOException;
public class DbTest {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
I downloaded the Platform Independent .zip version of the MySQL Connector from the following location:
http://dev.mysql.com/downloads/connector/j/
Then, after unzipping the file downloaded, I placed the resulting folder at the following location:
/java/mysql-connector-java-5.1.36
I am compiling my code from within the directory where it resides with the following command:
javac DbTest.java -cp /java/mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar
Finally, I am running my code with the following command:
java DbTest
The full stack trace from the event is as follows:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at DbTest.main(DbTest.java:6)
Thanks in advance for any help you can offer!
You need the JAR file on the classpath when you run your application; e.g.
java -cp /longpath/mysql-connector-java-5.1.36-bin.jar:. pkg.pkg.DbTest
(For a database driver, you don't need the JAR at compile time if you load the class using Class.forName(...). However, it does no harm including it on the compile-time classpath anyway.)

How to work with android studio for import and run project

I had download project from github and I want to import it into android studio. I tried several time but I cant run it. Any one give the step by step instruction to import the project because am new one for android studio.
Showing Error:
"C:\Program Files\Java\jdk1.8.0_25\bin\java" -ea -Didea.launcher.port=7532 -Didea.launcher.bin.path=D:\Users\SYS\AppData\Local\Android\android-studio\bin -Dfile.encoding=UTF-8 -classpath "D:\Users\SYS\AppData\Local\Android\android-studio\lib\idea_rt.jar;D:\Users\SYS\AppData\Local\Android\android-studio\plugins\junit\lib\junit-rt.jar;D:\Android By Timothy\Package tools\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\platforms\android-21\android.jar;D:\Android By Timothy\Package tools\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\platforms\android-21\data\res;D:\Android By Timothy\Package tools\adt-bundle-windows-x86_64-20131030\adt-bundle-windows-x86_64-20131030\sdk\tools\support\annotations.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 #C:\Users\SYS\AppData\Local\Temp\idea_junit7097204602616052537.tmp #w#C:\Users\SYS\AppData\Local\Temp\idea_working_dirs_junit3836436993075423504.tmp -socket54727
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
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)
... 3 more
Process finished with exit code 1
Now i got error:
11:51:25 UnsupportedMethodException
Failed to set up Android modules in project 'Telegram-master': Unsupported method: SourceProvider.getJniDirectories().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
I tried, and here is steps:
Git clone the project to you disk
Import project on your Android Studio.
There was one Error of gradle. Change the gradle version to latest 1.0.0, such that
"classpath 'com.android.tools.build:gradle:1.0.0'
Get your own api_id form here.
Follow the doc.
EDIT
For 'signingConfig.storeFile' does not exist problem:
1: Look if you have the debug.keystore in (~/.android or search your whole android folder). If you haven't got it. Look this (There is no debug.keystore in .android folder) for create a debug.keystore.
2: When you have the file. You have to copy the file('debug.keystore') on (Telegram/TMessagesProj/config).

MySql - Java - Class Not Found Exception

I am trying to use JDBC to access the MySql database on my computer. I get this error message
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at FunctionClass.special_function(FunctionClass.java:72)
at FunctionClass.<init>(FunctionClass.java:25)
at EvaluateFunctions.main(EvaluateFunctions.java:12)
I've seen on the other posts that this is due to the fact that the driver is not in the lib directory of the JDK. I tried that and it still doesn't work. I added the *.jar file to my "/usr/lib/default-java/lib/" folder on Xubuntu. I am not using any kind of servers. Here is my code that connects to the database:
Class.forName("com.mysql.jdbc.Driver");
Does anyone know what I am missing here?
Thanks for all the help in advance.
If you are using eclipse or some ide you can add the jar files to your build path.
It can be done by checking this link for eclipse. https://stackoverflow.com/a/27085441/4083590
If you are using command prompt you should add the jar files to your CLASSPATH. It can be done as shown below.
Linux:
CLASSPATH=$CLASSPATH;{Current working directory};{Direct Path to .jar file}
CLASSPATH=$CLASSPATH;/home/users/xyz/workspace/;/home/users/xyz/workspace/xyz.jar
Note: ./ can be used to signify current working directory
Windows:
set CLASSPATH=%CLASSPATH%:{Current working directory}:{Direct path to .jar file}
set CLASSPATH=%CLASSPATH%:C:\users\xyz\workspace:C:\users\xyz\workspace\xyz.jar
After doing this you would be able to compile your program.

Docx4j Class Not Found Error

I am trying to run a tutorial from here Office Open XML. I have downloaded the Docx4j library and added it to the netbeans as a library.
the code snippet is given below
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
public class OfficeOpen {
public static void main(String[] args) throws Docx4JException {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
wordMLPackage.save(new java.io.File("src/main/files/HelloWord1.docx"));
}
}
when I run the above example I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.docx4j.openpackaging.Base.<clinit>(Base.java:43)
at officeopen.OfficeOpen.main(OfficeOpen.java:24)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
looks like the JVM cannot find a class at run time, any suggestion. I am using Netbeans 8.0
You are missing some libraries that docx4j depends on. See http://htmlpreview.github.io/?https://github.com/plutext/docx4j/blob/master/docs/Docx4j_GettingStarted.html at docx4j dependencies.
Indeed you are missing slf4j that docx4j uses for for logging: http://www.docx4java.org/docx4j/docx4j-3_2_0/dependencies/slf4j-api-1.7.5.jar
Possibly you'll need many others.
I think this are all the dependencies, althought you may not need all of them: http://www.docx4java.org/docx4j/docx4j-3_2_0/dependencies/

NoClassDefFoundError exception

I got trouble in using my external jar file even if I put it inside class path correctly.
My external jar file is in the D: drive and my class path is "C:\Program Files\Java \jdk1.7.0_51\bin; D:\webcam-capture-0.3.10-RC6.jar; C:\Program Files\Java\jdk1.7.0_51\lib;" so please help me solve the problem. Below is my code:
import com.github.sarxos.webcam.Webcam;
import javax.swing.JOptionPane;
public class DetectWebcamExample {
public static void main(String[] args) {
try {
Webcam webcam = Webcam.getDefault();
if (webcam != null) {
System.out.println("Webcam: " + webcam.getName());
} else {
System.out.println("No webcam detected");
}
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
the exeption detail is
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:40)
at test.Test.main(Test.java:20)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 2 more
Java Result: 1
i amend the path with "C:\Program Files\Java\jdk1.7.0_51\bin;" and classpath "D:\webcam-capture-0.3.10-RC6.jar;." but the exception is still there
How can I solve this problem?
Java has found com.github.sarxos.webcam.Webcam so you have successfully added that JAR to the classpath.
What's happening now is that Webcam is trying to use a log4j class, and that's not on the classpath.
This is common - package A needs package B; package B needs package C; and you can spend a while finding JARs to fulfil chains of dependencies.
In this case you're going to need two log4j jars - log4j-api and one of a choice of log4j implementation jars. See the log4j web page for details.
If the hunt for dependency jars starts getting silly, consider using Maven or Ivy to handle your dependencies for you.

Categories