java - JavaFX - Load Song object fields from text file into an ArrayList of Songs -
i trying populate arraylist of song objects songs have in text file. running many issues , confused. can me out? code populatelist method
public arraylist<design.song> populatelist() throws filenotfoundexception{ arraylist<song> songlist = new arraylist<>(); scanner sc = new scanner(new file("/application/songs.txt")); while(sc.hasnext()){ song song1 = new song(sc.nextline(), sc.nextline(), sc.nextline(), integer.parseint(sc.nextline())); songlist.add(song1); } return songlist; } and here controller:
package design; import application.main; import java.io.bufferedreader; import java.io.file; import java.io.filenotfoundexception; import java.io.filereader; import java.net.url; import java.util.arraylist; import java.util.list; import java.util.resourcebundle; import java.util.scanner; import javafx.collections.fxcollections; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.listview; public class controller implements initializable { @fxml private listview<song> listviewofsongs; list<song> songarray = main.populatelist(); @override public void initialize(url url, resourcebundle rb) { listviewofsongs.setitems(fxcollections.observablelist(songarray)); } public void addsong(song song){ songarray.add(song); } }
the problems running had fact trying implement code directly inside controller class. need implement code inside sort of method javafx controller.
Comments
Post a Comment