Hallo zusammen, ich bin aktuell dabei, ein kleines Projekt zu realisieren, in dem ich CSV Dateien einlesen und im Array speichern möchte.
Jedes mal, wenn ich versuche, eine Datei einzulesen, kriege ich diese Fehlermeldung: java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVParser
Der Error fliegt in der Klasse CSVReader, in der Zeile:
Ich arbeite mit der Apache Commons Library.
Vielleicht hat ja jemand eine Idee, wie das ganze zu lösen sein?
Grüße Jonah/Reakz
Jedes mal, wenn ich versuche, eine Datei einzulesen, kriege ich diese Fehlermeldung: java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVParser
Der Error fliegt in der Klasse CSVReader, in der Zeile:
Java:
try (
Reader reader = Files.newBufferedReader(Paths.get(path, sensorPath));
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);
) {
Ich arbeite mit der Apache Commons Library.
Vielleicht hat ja jemand eine Idee, wie das ganze zu lösen sein?
Grüße Jonah/Reakz
Java:
package eu.jonah.main;
public class Main {
static GUI Interface;
public static void main(String[] args) {
Interface = new GUI();
}
}
Code:
package eu.jonah.main;
import java.awt.*;
import java.awt.event.*;
public class GUI extends Frame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 5319542784686888394L;
Computing Comp;
private Label label1 = new Label();
private Label label2 = new Label();
private Label label3 = new Label();
private Label label4 = new Label();
private Label label5 = new Label();
private static Label label6 = new Label();
private Label label7 = new Label();
private TextField textField1 = new TextField();
private TextField textField2 = new TextField();
private TextField textField3 = new TextField();
private TextField textField4 = new TextField();
private Button button1 = new Button();
public GUI() {
super("Stridelength-analysis");
int frameWidth = 546;
int frameHeight = 350;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Panel cp = new Panel(null);
add(cp);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
label1.setBounds(80, 8, 253, 32);
label1.setText("Interface");
label1.setFont(new Font("MS Sans Serif", Font.BOLD, 18));
cp.add(label1);
label2.setBounds(8, 36, 205, 24);
label2.setText("Parameter");
label2.setFont(new Font("MS Sans Serif", Font.BOLD, 14));
cp.add(label2);
label3.setBounds(16, 66, 100, 24);
label3.setText("Name:");
label3.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(label3);
label4.setBounds(16, 96, 100, 16);
label4.setText("leg length: ");
label4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(label4);
label5.setBounds(16, 126, 100, 16);
label5.setText("lower leg length: ");
label5.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(label5);
label7.setBounds(16, 156, 100, 16);
label7.setText("Datapath: ");
label7.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(label7);
label6.setBounds(8, 250, 300, 24);
label6.setText("");
label6.setFont(new Font("MS Sans Serif", Font.BOLD, 14));
cp.add(label6);
textField1.setBounds(128, 66, 161, 24);
textField1.setText("");
cp.add(textField1);
textField2.setBounds(128, 96, 161, 24);
textField2.setText("");
cp.add(textField2);
textField3.setBounds(128, 126, 161, 24);
textField3.setText("");
cp.add(textField3);
textField4.setBounds(128, 156, 161, 24);
textField4.setText("");
cp.add(textField4);
button1.setBounds(336, 216, 179, 25);
button1.setLabel("Calculate");
cp.add(button1);
button1.addActionListener(this);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent Event) {
Object Source = Event.getSource();
if (Source == button1) {
if (!textField1.getText().equals("") && !textField2.getText().equals("") && !textField3.getText().equals("") && !textField4.getText().equals("")) {
if (Computing.isNumeric(textField2.getText()) && Computing.isNumeric(textField3.getText()) ) {
String name = textField1.getText();
float legLength = Float.parseFloat(textField2.getText());
float lowerLegLength = Float.parseFloat(textField3.getText());
String path = textField4.getText();
Computing.run(name, legLength, lowerLegLength, path);
textField1.setText("");
textField2.setText("");
textField3.setText("");
textField4.setText("");
} else {
setLabel6("(Lower) leg lenth must be numeric");
// Computing.protocoll("Leg length not numeric");
}
} else {
setLabel6("Please enter all values!");
//Computing.protocoll("Not all values given");
}
}
}
public static void setLabel6(String pText) {
label6.setText(pText);
}
}
Code:
package eu.jonah.main;
import java.io.IOException;
public abstract class Computing {
/*
static float[][] sensor1 = new float[7][18000];
static float[][] sensor2 = new float[7][18000];
static float[][] sensor3 = new float[7][18000];
static float[][] sensor4 = new float[7][18000];
static float[][] sensor5 = new float[7][18000];
*/
static float[][][] sensors = new float [5][7][18000];
static float[][] strideLength = new float[3][500];
public Computing() {
}
/*
* Order in the array/excel sheet acceleration & angles: [sensor number], time, x, y, z (degree),
* x, y, z (acceleration) stridelength: time, stridelength, velocity
*/
public static void run(String name, float legLength, float Unterschenkel, String path) {
GUI.setLabel6("Parameters taken sucessfully");
/*
protocoll("Parameters taken sucessfully");
protocoll("Name: " + name);
protocoll("Leglength: " + legLength);
protocoll("Unterschenkel: " + Unterschenkel);
protocoll("Datapath: " + path);
*/
//for(int i = 1; i < 6; i++) {
try {
new CSVReader(path, 1);
} catch (IOException e) {
GUI.setLabel6("Invalid path/file");
e.printStackTrace();
}
protocoll("Read sensor" + 1);
//System.out.println(sensors);
//}
}
public static void protocoll(String pText) {
GUI.setLabel6(pText);
System.out.println(pText);
}
public static boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
Double.parseDouble(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public float getSensors(int i, int j, int k) {
return sensors[i][j][k];
}
public static void setSensors(float value, int i, int j, int k) {
sensors[i][j][k] = value;
}
/*
public float getSensor1(int i, int j) {
return sensor1[i][j];
}
public static void setSensor1(float value, int i, int j) {
sensor1[i][j] = value;
}
public float getSensor2(int i, int j) {
return sensor2[i][j];
}
public static void setSensor2(float value, int i, int j) {
sensor2[i][j] = value;
}
public float getSensor3(int i, int j) {
return sensor3[i][j];
}
public static void setSensor3(float value, int i, int j) {
sensor3[i][j] = value;
}
public float getSensor4(int i, int j) {
return sensor4[i][j];
}
public static void setSensor4(float value, int i, int j) {
sensor4[i][j] = value;
}
public float getSensor5(int i, int j) {
return sensor5[i][j];
}
public static void setSensor5(float value, int i, int j) {
sensor5[i][j] = value;
}
*/
public float getStrideLength(int i, int j) {
return strideLength[i][j];
}
public void setStrideLength(float value, int i, int j) {
strideLength[i][j] = value;
}
}
Code:
package eu.jonah.main;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
public class CSVReader {
public CSVReader(String path, int sensor) throws IOException {
String sensorPath = sensor + ".csv";
Computing.protocoll("Trying to load sensor " + sensor);
try (
Reader reader = Files.newBufferedReader(Paths.get(path, sensorPath));
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);
) {
for (CSVRecord csvRecord : csvParser) {
// Accessing Values by Column Index
String sampleTime = csvRecord.get(1);
String EulerX = csvRecord.get(2);
String EulerY = csvRecord.get(3);
String EulerZ = csvRecord.get(4);
String accelerationX = csvRecord.get(5);
String accelerationY = csvRecord.get(6);
String accelerationZ = csvRecord.get(7);
pass(sampleTime, sensor, 0, (int) csvRecord.getRecordNumber());
pass(EulerX, sensor, 1, (int) csvRecord.getRecordNumber());
pass(EulerY, sensor, 2, (int) csvRecord.getRecordNumber());
pass(EulerZ, sensor, 3, (int) csvRecord.getRecordNumber());
pass(accelerationX, sensor, 4, (int) csvRecord.getRecordNumber());
pass(accelerationY, sensor, 5, (int) csvRecord.getRecordNumber());
pass(accelerationZ, sensor, 6, (int) csvRecord.getRecordNumber());
System.out.println("Record No - " + csvRecord.getRecordNumber());
}
}
catch (IOException e) {
Computing.protocoll("Invalid path/file!");
}
}
public void pass(String value, int sensor, int x, int y) {
if (y < 11 && y > 18011 && x < 1 && x > 7) {
if (Computing.isNumeric(value)) {
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
Computing.setSensors(Float.parseFloat(value), sensor, x - 1, y - 1);
}
}
}
public void oldpass(String value, int sensor, int x, int y) {
if (y < 11 && y > 18011 && x < 1 && x > 7) {
if(Computing.isNumeric(value)) {
Computing.setSensors(Float.parseFloat(value), sensor, x-1, y-1);
}
}
}
}