Hi!
i just started learning java ;]
i wanna write bank accounts program
i get an error i know its in login method but i dont know where :\
cd u please help me with this one
the code below reads user data from a file then sets the vars declared in a class
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 1
at konta_bankowe.U zytkownik.login (Uzytkownik.jav a)
at konta_bankowe.K onto.main(Konto .java)
my code for user
i just started learning java ;]
i wanna write bank accounts program
i get an error i know its in login method but i dont know where :\
cd u please help me with this one
the code below reads user data from a file then sets the vars declared in a class
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 1
at konta_bankowe.U zytkownik.login (Uzytkownik.jav a)
at konta_bankowe.K onto.main(Konto .java)
my code for user
Code:
package konta_bankowe;
import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.io.IOException;
import java.util.*;
import javax.swing.*;
public class Uzytkownik {
private String IDuzytkownika;
private String haslo;
private String numerKonta;
private String imie;
private String nazwisko;
public Uzytkownik(){};
public void setUserID(String id){
IDuzytkownika=id;
}
public void setHaslo(String h){
haslo=h;
}
private void setNumerKonta(String n_k){
numerKonta =n_k;
}
private void setImie(String i){
imie=i;
}
private void setNazwisko(String n){
nazwisko=n;
}
public void displayUserData(){
System.out.println("Numer konta"+numerKonta+" "+imie+" "+nazwisko);
}
public boolean login(){
Map<String,String> map = new HashMap<String,String>();
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(IDuzytkownika+".txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine = br.readLine()) != null) {
String[] dane=strLine.split(":");
map.put(dane[0],dane[1]);
}
in.close();
}catch (FileNotFoundException e) {
System.err.println("Nie ma takiego uzytkownika(File not found!)");
}catch (IOException e) {
System.err.println(e);}
if((map.get("id")==IDuzytkownika) && (map.get("haslo")==haslo)){
String numer_konta=map.get("numer konta");
String i=map.get("imie");
String n=map.get("nazwisko");
setNumerKonta(numer_konta);
setImie(i);
setNazwisko(n);
return true;
}else{return false;}
}
}
Comment