Previous in Forum: Thesis for Final Year   Next in Forum: Solution for App Start-up
Close
Close
Close
2 comments
Rate Comments: Nested
Participant

Join Date: Mar 2020
Posts: 2

How Do I use correctly Java CSVtoBean

03/25/2020 2:14 PM

I am using Jdeveloper to create a small software which reads Weatherdata from a .csv file and proceses it .

Unfortunatelly i am stuck at the first step, reading data from file . Keep getting back the following Exception : Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/MultiValuedMap

Please see attached my progress so far , please feel free to edit or comment .

public class Main {

/**

* @param args

*

*/

@SuppressWarnings({"rawtypes", "unchecked"})

public static void main(String[] args) throws IOException {

String fileName = "C:\\JDeveloper\\mywork\\Csv reading\\Project1\\wdata1.csv";

Path myPath = Paths.get(fileName);

try (BufferedReader br = Files.newBufferedReader(myPath, StandardCharsets.UTF_8)) {

HeaderColumnNameMappingStrategy<Read> strategy = new HeaderColumnNameMappingStrategy<>();

strategy.setType(Read.class);

CsvToBean toBean = new CsvToBeanBuilder(br).withType(Read.class)

.withMappingStrategy(strategy)

.withIgnoreLeadingWhiteSpace(true)

.build();

List<Read> Data = toBean.parse();

Data.forEach(System.out::println);

}

}

Also have a different class with the column names :

public class Read {

@CsvBindByName

private String stationid;

@CsvBindByName

private String datestamp;

@CsvBindByName

private double wgust;

@CsvBindByName

private int wdir;

// get, setters here

}

I have tried to import the neccesary files, tried most of the solution i found, but none of them seems to be working . I am really new to this, i would appreciate all the helps !

The file I am using looks like this :

Register to Reply
Pathfinder Tags: "Java" "CSV" "JavaBean"
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Guru

Join Date: Apr 2010
Location: About 4000 miles from the center of the earth (+/-100 mi)
Posts: 9910
Good Answers: 1141
#1

Re: How Do I use correctly Java CSVtoBean

03/25/2020 2:40 PM

"...a common error in Java which occurs if a ClassLoader is not able to find a particular class in the classpath while trying to load it."

Read more: https://www.java67.com/2012/08/what-is-noclassdeffounderror-in-java.html#ixzz6HjASTXhh

https://www.java67.com/2012/08/what-is-noclassdeffounderror-in-java.html

Register to Reply Score 1 for Good Answer
Participant

Join Date: Mar 2020
Posts: 2
#2
In reply to #1

Re: How Do I use correctly Java CSVtoBean

03/26/2020 11:13 AM

Thank you for your anwer managed to read the data in and displayed on screen.

Extended the code with a writer to write it in a .csv file.

My next step would be to calculate date specified averages/min's/max's of the Wind Data.

I have created a scanner to get the min and max date value from the user, but now i am stuck processing the data from the list .

Could you help me out or point me to relevant information ?

Register to Reply
Register to Reply 2 comments

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!

Previous in Forum: Thesis for Final Year   Next in Forum: Solution for App Start-up

Advertisement