2

I'm trying to read a CSV file using opencsv, I have imported everything and referenced the library in the classpath but i keep getting the ClassNotFoundException:

Here's my code:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import com.opencsv.CSVReader;

public class Main {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    CSVReader readActors;
    try {
        readActors = new CSVReader(new FileReader(new File("src\\prueba\\actors.csv")));

    String[] values = null;

        try {
            while ((values = readActors.readNext()) != null){
                String name =values[0];
                String bday = values[1];

                System.out.println("Name:" +name+", bday:" +bday); //check if reading is ok
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Here are the exceptions I'm getting:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils
at com.opencsv.CSVParser.<init>(CSVParser.java:207)
at com.opencsv.CSVReader.<init>(CSVReader.java:198)
at com.opencsv.CSVReader.<init>(CSVReader.java:180)
at com.opencsv.CSVReader.<init>(CSVReader.java:132)
at com.opencsv.CSVReader.<init>(CSVReader.java:72)
at prueba.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.ObjectUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 6 more

and the csv file looks like this and is located in the package 'prueba' as well as the Main class.

Margot Robbie,02/07/1990
Leonardo DiCaprio,11/11/1974
Brad Pitt,18/12/1963

1 Answer 1

2

Looks like you also need to add org.apache.commons.lang3 jar to the classpath. Maybe try this site https://commons.apache.org/proper/commons-lang/download_lang.cgi

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.