![]() |
| | Themen-Optionen |
| | Nach oben #1 |
| Neuer Benutzer Registriert seit: 04.01.2006
Beiträge: 1
|
Hallo, schreibe gerade ein Programm welches eine Csv-Datei ausliest und selbige tokenweise in einen mehrdim array speichern soll. theoretisch müsste es klappen. die datei gibts etc... alles wunderbar nur trotzdem wirft er eine nullpointerexpetion und ich hab keine ahnung wieso. Hier erst mal der Code: Code: /**
*
* @author pp0607
*
* Parser um Daten aus einer Csv-Datei aufzubereiten, 1 Zeile der Csv-Datei
* wird Tokenweise in eine Liste gespeichert.
*
*/
package starplot;
import java.io.*;
import java.util.*;
public class csvparser {
private File file;
private int dim ,array_dim,array_dim2;
private String delim, filemode, line, zeilen[][];
public csvparser(){
set_file ( "C:/Programme/Eclipse/workspace/pp0607/src/starplot/data.csv" );
set_delim ( ";" );
set_filemode( "r" );
dim = 0;
}
public csvparser( String dataname, String delim, String filemode ){
set_delim ( delim );
set_file ( dataname );
set_filemode( filemode );
dim = 0;
}
public void set_file( String path ){
this.file = new File( path );
}
public void set_delim( String delimiter ){
this.delim = delimiter;
}
public void set_filemode( String filemode ){
this.filemode = filemode;
}
public String get_delim(){
return delim;
}
public int get_dim(){
return dim;
}
public String get_filemode(){
return filemode;
}
public String[][] get_data(){
return zeilen;
}
/**
* Liest aus einer Csv-Datei die erste Zeile aus
*
* @throws IOException
* @throws IllegalArgumentException
*/
public void csvload() throws IOException, IllegalArgumentException {
if( file == null || !file.exists() ){
throw new IOException();
}
if( !( (filemode == "r") || (filemode == "rw") || (filemode == "rws") || (filemode == "rwd")) ){
throw new IllegalArgumentException();
}
RandomAccessFile fd = new RandomAccessFile( file,filemode );
line = fd.readLine();
array_dim = 0;
gettoken(line,array_dim);
array_dim++;
while( line != null ){
line = fd.readLine();
if (line != null){
System.out.println(line);
//gettoken(line,array_dim); // NPEXCEP
array_dim++;
}
}
System.out.println(array_dim);
fd.close();
}
/**
* Splittet die erste Zeile der Csv-Datei auf in Tokens und speichert
* sie in einer Liste
*
* @throws NullPointerException
*/
public void gettoken(String zeile,int array_dim ) throws NullPointerException{
StringTokenizer st = new StringTokenizer(zeile,delim);
if( st == null ){
throw new NullPointerException();
}
array_dim2 = 0;
while( st.hasMoreTokens() ){
zeilen[array_dim][array_dim2] = st.nextToken(); // NPEXCEP
array_dim2++;
}
if (array_dim2 == 0){
dim = array_dim2;
}
}
/**
* Testumgebung
*
* @param args
* @throws IOException
* @todo relativen pfad implementieren
*/
public static void main (String[] args) throws IOException{
csvparser getattr = new csvparser("C:/Programme/Eclipse/workspace/pp0607/files/data.csv",";","r");
getattr.csvload();// NPEXCEP
}
}
Code: Exception in thread "main" java.lang.NullPointerException
at starplot.csvparser.gettoken(csvparser.java:160)
at starplot.csvparser.csvload(csvparser.java:121)
at starplot.csvparser.main(csvparser.java:180)
Gruss Sengi |
| | |
![]() |
| Lesezeichen |
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
| Themen-Optionen | |
| |
Ähnliche Themen | ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Exception wird ignoriert. Stattdessen Standard-Fehlermeldung | Jojo | PHP-Programmierung | 11 | 17.11.2006 16:37 |
| throws Exception | trivial | Allgemeine Java-Programmierung | 2 | 19.10.2005 12:40 |
| Eine art Dump ohne Exception? | matt | Allgemeine Java-Programmierung | 1 | 20.07.2005 05:09 |
| Array als Parameter und Exception | punachino | Allgemeine Java-Programmierung | 2 | 25.05.2005 02:23 |
| Exception in Interface abfangen?! | `B | Allgemeine Java-Programmierung | 6 | 12.04.2005 20:32 |