I am trying to save an object, that is created from a file, into an arraylist and I am having troubles with doing exactly that in a three-class program. I'm getting an error telling me to create constructors, but when I auto create them I get an error saying: Constructor cannot be applied to given types
. I am not sure what it means. In short - I've been at this thing for hours now and cannot figure it out.
public class Darbuotojas {
String vardas;
String pareigos;
int gm;
Float atlyginimas;
public Darbuotojas(String vardas, String pareigos, int gm, Float atlyginimas){
this.vardas = vardas;
this.pareigos = pareigos;
this.gm = gm;
this.atlyginimas = atlyginimas;
}
}
Here is the code where I read the file, and try to put Objects Darbuotojas
into an ArrayList:
public class Viskas extends Darbuotojas{
String gm1;
String atlyginimas1;
ArrayList<Darbuotojas> darbuotojai = new ArrayList<Darbuotojas>();
public void failas(String fl) throws IOException{
//Failu nuskaitymas po zodi
File file = new File(fl);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
while ((line = br.readLine()) != null){
String [] tokens = line.split("/");
vardas = tokens[0];
pareigos = tokens[1];
gm1 = tokens[2];
gm = Integer.parseInt(gm1);
atlyginimas1 = tokens[3];
atlyginimas = Float.parseFloat(atlyginimas1);
System.out.print(vardas.toUpperCase() + " ");
System.out.print(pareigos.toUpperCase() + " ");
System.out.print(gm + " ");
System.out.println(atlyginimas);
Darbuotojas drb = new Darbuotojas(vardas,pareigos,gm,atlyginimas);
darbuotojai.add(drb);
System.out.println(drb);
}
br.close();
}
catch(FileNotFoundException e){
}
}
}
And here is the main function:
public static void main(String[] args) throws IOException {
Scanner kb = new Scanner(System.in);
System.out.println("Iveskite duomenu vailo pavadinima su failo tipu: ");
String fl = kb.next();
Viskas ddd = new Viskas();
ddd.failas(fl);
}
I'm sorry about all the variables being in Lithuanian, but I don't think it changes anything code readability wise.