L
LexDanny
Gast
Hallo!
Ich habe folgendes Java-Prog geschrieben. Allerdings gibt es ein Problem mit der Ausgabe in der Methode open. Ich erhalte eine NullPointerException(für Zeile 65), weiß aber nicht wieso!
Die Datei passwd.txt sieht so aus(hier nur die 1. Zeile
Das Problem müsste sich in Zeile 53 und 65-71 liegen. Allerdings weiß ich nicht, wie ich es besser machen könnte!
Schon mal danke im vorraus!
Lex
Ich habe folgendes Java-Prog geschrieben. Allerdings gibt es ein Problem mit der Ausgabe in der Methode open. Ich erhalte eine NullPointerException(für Zeile 65), weiß aber nicht wieso!
Die Datei passwd.txt sieht so aus(hier nur die 1. Zeile
Code:
stiebitz:CFzc0M/4oDZa.:5316:5100:Ralf Stiebitz:/home/stud/2006/stiebitz:/bin/bash
Das Problem müsste sich in Zeile 53 und 65-71 liegen. Allerdings weiß ich nicht, wie ich es besser machen könnte!
Schon mal danke im vorraus!
Lex
Code:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Account
{
public static int index;
public int uid;
public int gid;
public String login_name;
public String password, user_name, directory, shell;
public static void main(String[] args)
{
open("passwd.txt");
}
Account(String login_name, String password, String uid, String gid, String user_name, String directory, String shell)
{
this.login_name=login_name;
this.password=password;
this.uid=Integer.parseInt(uid);
this.gid=Integer.parseInt(gid);
this.user_name=user_name;
this.directory=directory;
this.shell=shell;
}
public static Account[] open(String filename)
{
index=0;
Vector<Account> list=new Vector<Account>();
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(filename)) );
String s;
while ((s=in.readLine())!=null)
{
StringTokenizer tokenizer=new StringTokenizer(s, ":");
String login_name= tokenizer.nextToken();
String password= tokenizer.nextToken();
String uid= tokenizer.nextToken();
String gid= tokenizer.nextToken();
String user_name= tokenizer.nextToken();
String directory= tokenizer.nextToken();
String shell= tokenizer.nextToken();
list.add(index, new Account(login_name, password, uid, gid, user_name, directory, shell));
index=index+1;
}
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();}
Account[] result=new Account[list.size()];
int i=0;
while (i!=(index-1))
{
result[i].login_name=list.elementAt(i).login_name;
result[i].password=list.elementAt(i).password;
result[i].uid=list.elementAt(i).uid;
result[i].gid=list.elementAt(i).gid;
result[i].user_name=list.elementAt(i).user_name;
result[i].directory=list.elementAt(i).directory;
result[i].shell=list.elementAt(i).shell;
i=i+1;
}
return result;
}
}