Java method help
- by dalton conley
Ok, so I'm working on a project for a class I'm taking.. simple music library. Now I'm having some issues, the main issue is I'm getting "non-static method cannot be referenced from a static context"
Here is a function I have
public void addSong() {
Scanner scan = new Scanner(System.in);
Song temp = new Song();
int index = countFileLines(Main.databaseFile);
index = index + 2;
temp.index = index;
System.out.print("Enter the artist name: ");
temp.artist.append(scan.next());
}
Now thats in a class file called LibraryFunctions. So I can access it with LibraryFunctions.addSong();
Now I'm trying to run this in my main java file and its giving me the error, I know why the error is happening, but what do I do about it? If I make addSong() a static function then it throws errors at me with the Song temp = new Song() being static. Kind of ironic.
Much help is appreciated on this!