Song database null pointer -
i'm creating simple music database userinterface.class, song.class, songdatabase.class , playlist.class. song object(artist, name, duration, filesize) input user meant stored in nearest dataslot in songdatabase , i'm receiving null pointer @ user input "filesize"
java.lang.nullpointerexception @ songdatabase.addsong(songdatabase.java:27) @ userinterface.userimport(userinterface.java:143) @ userinterface.main(userinterface.java:61)
i'm having trouble storing refrence of song object in playlist
class's here;
if @ great thanks.
the songdatabase;
public class songdatabase {
userinterface intface = new userinterface(); song songdata = new song(); private static song a; private static song b; private static song c; private static song d; public songdatabase() { = null; b = null; c = null; d = null; } public void addsong(string dataartist, string dataname, double dataduration, int datafilesize) //add song database constructor according nearest free slot// { if (a==null) { setdata(a.songartist, a.songname, a.songduration, a.songfilesize); a.songartist=dataartist; a.songname=dataname; a.songduration=dataduration; a.songfilesize=datafilesize; } else if (b==null) { setdata(b.songartist, b.songname, b.songduration, b.songfilesize); b.songartist=dataartist; b.songname=dataname; b.songduration=dataduration; b.songfilesize=datafilesize; } else if (c==null) { setdata(c.songartist, c.songname, c.songduration, c.songfilesize); c.songartist=dataartist; c.songname=dataname; c.songduration=dataduration; c.songfilesize=datafilesize; } else if (d==null) { setdata(d.songartist, d.songname, d.songduration, d.songfilesize); d.songartist=dataartist; d.songname=dataname; d.songduration=dataduration; d.songfilesize=datafilesize; } else { system.out.println("error: there no free space in database"); } } public void setdata( string setartist, string setname, double setduration, int setfilesize) //exchange of user input info. local variables// { setartist = intface.artist; setname = intface.name; setduration = intface.duration; setfilesize = intface.filesize; } public static song areturn() { return a; } public static string areturnartist() { return a.songartist; } public static song breturn() { return b; } public static string breturnartist() { return b.songartist; } public static song creturn() { return c; } public static string creturnartist() { return c.songartist; } public static song dreturn() { return d; } public static string dreturnartist() { return d.songartist; } public string removesongdata() { if(intface.removesong()==0) { system.out.println(a.songname+" by: "+a.songartist+" has been deleted database.."); = null; }else if(intface.removesong()==1) { system.out.println(b.songname+" by: "+b.songartist+" has been deleted database.."); b = null; }else if(intface.removesong()==2) { system.out.println(c.songname+" by: "+c.songartist+" has been deleted database.."); c = null; }else if(intface.removesong()==3) { system.out.println(d.songname+" by: "+d.songartist+" has been deleted database.."); d = null; }else{ system.out.println("error: check input choice"); } return removesongdata(); } public string dataslotcheck() //scan system , return song objects// { string finalscan; if (a==null&&b==null&&c==null&&d==null) { finalscan=("there no music stored in database."); } else if (d==null&&c==null&&b==null) { finalscan=("slot 0:"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfilesize); } else if (d==null&&c==null) { finalscan= ("slot 0 :"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfilesize+ "slot 1 :"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfilesize); } else if (d==null) { finalscan= ("slot 0 :"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfilesize+ "slot 1 :"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfilesize+ "slot 2 :"+c.songartist+":"+c.songname+":"+c.songduration+":"+c.songfilesize); } else { finalscan= ("slot 0 :"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfilesize+ "slot 1 :"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfilesize+ "slot 2 :"+c.songartist+":"+c.songname+":"+c.songduration+":"+c.songfilesize+ "slot 3 :"+d.songartist+":"+d.songname+":"+d.songduration+":"+d.songfilesize); } return (finalscan); }
}
Comments
Post a Comment