Hello guys!
This is my "Call" class (without the setters and getters):
import java.util.ArrayList; public class Call { private String callingNumber; private String dialedNumber; private String datetime; private int duration; static ArrayList <Call> calls = new ArrayList<Call>(); public Call (String callingNumber , String dialedNumber, String datetime, int duration) { this.callingNumber = callingNumber; this.dialedNumber = dialedNumber; this.datetime = datetime; this.duration = duration; calls.add(this); }
My application needs to read a text file and then create the corresponding "Call". The "document.txt" keeps the data of a call in every line (callingNumber, dialedNumber, datetime, duration)
(e.g. 4748832, 462346214, 01-01-2012 11:55:33, 126
64364366, 62346547, 03-03-2012 11:55:33, 65 ) .
I thought that i should "read" the line (in my main method) and add it to the calls ArrayList. Something like this:
public static void main (String args[]) throws IOException { try { File file1 = new File("C:\\...\\document.txt"); Scanner Filereader1 = new Scanner(file1); while (Filereader1.hasNextLine()) { String a = Filereader1.next(); Call.calls.add(a) } } catch (FileNotFoundException e) { System.out.println("error" + e); } }
This is not working because "Call.calls.add()" method can only add "Call" objects which the line of the document is not.
Any suggestions?
Thanks.