Apache POI Workbook class not found - java

First, I want let you know what I'm using:
Eclipse IDE 2018-09 (4.9.0) Java-SE 10
Apache POI 4.0.0-20180907
I don't mixing any JARs files with other version and I add to my project all the JARs in the folder except "poi-examples-4.0.0".
Let take a look of this code:
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
public class Program
{
public static void main(String[] args)
{
Workbook workbook = new HSSFWorkbook();
}
}
I getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
at Program.main(Program.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
And if I'm trying this code:
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Program
{
public static void main(String[] args)
{
Workbook workbook = new XSSFWorkbook();
}
}
I getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook
at Program.main(Program.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Can someone can explain me what I'm doing wrong?

Related

Vert.x JDBC client: Could not load the required implementation

I'm trying to connect to a database with the vert.x JDBC client:
import io.vertx.core.AbstractVerticle;
import io.vertx.core.*;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;
public class MainVerticle extends AbstractVerticle {
#Override
public void start(Promise<Void> startPromise) throws Exception {
JDBCPool pool = JDBCPool.pool(
vertx,
new JDBCConnectOptions()
.setJdbcUrl("jdbc:sqlserver://some_ip")
.setUser("user")
.setPassword("password"),
new PoolOptions().setMaxSize(16)
);
pool
.query("SELECT * FROM test")
.execute()
.onFailure(e -> {
System.out.println(e.toString());
})
}
}
This gives me the result:
java.sql.SQLException: Could not load the required implementation
I assume, that this is caused by line 53 here.
However, I don't really understand what the code there is doing.
Complete stacktrace:
java.sql.SQLException: Could not load the required implementation
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:53)
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:33)
at io.vertx.jdbcclient.impl.AgroalCPDataSourceProvider.getDataSource(AgroalCPDataSourceProvider.java:73)
at io.vertx.ext.jdbc.impl.JDBCClientImpl.createDataSource(JDBCClientImpl.java:274)
at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$getDataSourceHolder$6(JDBCClientImpl.java:256)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:160)
at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:96)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:158)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.ClassNotFoundException: io.agroal.pool.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:49)
... 12 more
The error can be resolved by adding
implementation group: 'io.agroal', name: 'agroal-pool', version: '1.0'
to the build.gradle.

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application

I'm trying to execute a .jar file which I produced from a JavaFX project (i already set the VM Options in Intellij with module path and modules to include) but I keep getting this error
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at main.Launcher.main(Launcher.java:5)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 10 more
I also have a Launcher class, which Main method just does Main.main(args), where Main is the class that extends Application.
What can i do more?
This is the main class of my project
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/InserimentoPorta.fxml"));
primaryStage.setTitle("EP Miner");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}catch (IOException e){
System.out.println(e.getMessage());
System.exit(-1);
}
}
public static void main(String[] args) {
launch(args);
}
}
And there are 3 controllers, one for each of my fxml file (i'm not posting the controllers code because the question would be too long and i don't think it's necessary to solve this problem)

java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver at Driverbasic.Driverbasics.main(Driverbasics.java:12)

i am getting the above error .I have import all the libs related to selenium and java .Here is the code that i have written
package Driverbasic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Driverbasics {
public static void main (String args [])
{
System.setProperty("webdriver.gecko.driver", "/home/user/Downloads/geckodriver-v0.29.1-linux64");
WebDriver driver = new FirefoxDriver();
}
}
Here is the error i am getting
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
at Driverbasic.Driverbasics.main(Driverbasics.java:12)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.firefox.FirefoxDriver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I have attached the screenshot for the same .enter image description here
enter image description here
Any help would be really appreciated .

Error: A JNI error has occurred, please check your installation

I am doing following test and got JNI error. This happened with TestNG, I can run this test with with
public void main(String[] args) but not with TestNG.
package restAssurePractice;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
public class ApiBasics {
#Test
public static void restAssuredVerification() {
//baseurl
RestAssured.baseURI="https://reqres.in/";
given().
param("page=2").
when().
get("/api/users").
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().
body("data[0].last_name",equalTo("Michael"));
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

Java program reading data from a excel file throws and error..need help to resolve

I'm using XSSF user model to read data in excel file and print them. I have added all POI Jar files in to Java Build Path --> Libraries. But still i'm getting same error. Please help me to resolve this issue.
package com.javalab.sample;
import java.io.*;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadFromExcel3 {
public static void main(String[] args) {
try {
File excel1 = new File ("C:\\TestData\\test.xlsx");
FileInputStream fis1 = new FileInputStream(excel1);
XSSFWorkbook xssfWork = new XSSFWorkbook(fis1);
XSSFSheet sheet1 = xssfWork.getSheetAt(0);
Iterator<Row> rowItr = sheet1.rowIterator();
while ( rowItr.hasNext() )
{
XSSFRow row = (XSSFRow) rowItr.next();
System.out.println("ROW:-->");
Iterator<Cell> cellItr = row.cellIterator();
while ( cellItr.hasNext() )
{
XSSFCell cell = (XSSFCell) cellItr.next();
System.out.println("CELL:-->"+cell.toString());
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Exception
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/xmlbeans/XmlException
at com.javalab.sample.ReadFromExcel3.main(ReadFromExcel3.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
You forgot to add the xmlbeans-xxx.jar coming with the POI binary distribution (under ooxml-lib) in your classpath.

Categories

Resources