I just want to know what's the mistake here or what I shoul add or quit from my code.
I want to create an ArrayList from a scanner, but i can't. If I create an ArrayList without specifying the type it works. What's the prob? I've already got a class Song.
When I print my 1st try, the Array is full of "nulls". When I print the 2nd try, the Array is just as I need it. How can I do that my 1st try shows the same print as try 2?
Thanks!!
ArrayList<Song> can = new ArrayList<Song>(); // 1st try
ArrayList can1 = new ArrayList(); /2nd try
Song song;
Scanner scan = null;
try {
scan = new Scanner(new FileReader("src/arrayList/Song.dat"));
while (scan.hasNext()) {
can.add(Song(scan.next())); // 1st try
can1.add(scan.next()); // 2nd try
}
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (InputMismatchException e) {
System.err.println(e);
} catch (java.util.NoSuchElementException e) {
System.err.println(e);
}
finally {
scan.close();
}