Exception in thread

I keep getting this error and i cant figure out what is wrong.

Exception in thread "main" java.lang.NullPointerException

at pmusic.MusicApp.main(MusicApp.java:93)

Java Result: 1

here is my code:

package pmusic;

import java.io.*;

public class MusicApp

{

public static void main(String[] args)

{Artist[] myArtists = new Artist[1];

Albums[] myAlbums = new Albums[2];

Songs[] mySongs = new Songs[12];

int s=0, al=0, ar=0, count=0;

try

{

String line = "";

BufferedReader in = new BufferedReader(new FileReader("small list.csv"));

while (((line = in.readLine()) != null) && (count<23))

{

String[] fields = line.split(",");

{

if (fields[0]=="")

{

if (fields[1]=="")

{

int trackNumber = Integer.parseInt(fields[4]);

String trackName = fields[5];

mySongs[s] = new Songs(trackName, trackNumber);

s++;

}

else

{String album = fields[1];

int rank = Integer.parseInt(fields[2]);

int year = Integer.parseInt(fields[3]);

myAlbums[al] = new Albums(album, rank, year, mySongs);

s=0;

al++;

}

}

else

{

String artistname = fields[0];

myArtists[ar] = new Artist(artistname, myAlbums);

al=0;

}

}

}

}

catch (IOException e)

{

System.out.println("There was a problem with the file");

e.printStackTrace();

}

System.out.println(mySongs[0].toString());

}

}

the error is on the System.out.println(mySongs[0].toString());

can anyone help?

[1677 byte] By [imanewbea] at [2007-11-27 5:20:48]
# 1
hmmmm not sure man?
confusedboya at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 2
could u post the code again using the code button this time. Its difficult to understand where ur loops starts n ends.
-...icedT...-a at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 3

The error indicates that mySongs[0] is null i.e. not initialized. You have intilised mySongs array objects under the condition

if (fields[0]=="")

{

if (fields[1]=="")

{

...

}

I think this condition is never satisfying so the mySongs[0] is not initialising. Please check whether the above if condition is satisfying and you are actually initialising the mySongs objects... You can use the debug facility of an IDE or just give a System.out.println to check whether the flow is entering into this conditions..

Hope it helps :)

diptaPBa at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 4

This is the info i am sending in.

3 Doors Down,Away From The Sun,5,2002,1,When I'm Gone

,,,,2,Away From The Sun

,,,,3,The Road I'm On

,,,,4,Ticket To Heaven

,,,,5,Running Out Of Days

,,,,6,Here Without You

,,,,7,I Feel You

,,,,8,Dangerous Game

,,,,9,Changes

,,,,10,Going Down In Flames

,,,,11,Sarah Yellin'

,,,,12,This Time

,Better Life,6,2000,1,Kryptonite

,,,,2,Loser

,,,,3,Duck And Run

,,,,4,Not Enough

,,,,5,Be Like That

,,,,6,Life Of My Own

,,,,7,Better Life

,,,,8,Down Poison

,,,,9,By My Side

,,,,10,Smack

,,,,11,So I Need You

i have to check if its null.

imanewbea at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 5
Hi,if (fields[0]==""){if (fields[1]==""){...}It is definitely the problem. You will never get true here. You should use fields[n].equals(摂) instead.
_Dima_a at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 6
ignore this postMessage was edited by: diptaPB
diptaPBa at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 7
your array of songs is empty
georgemca at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 8
plz use code tags and be sure your SONGS array songs[0] refer to Object
eaajea at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...
# 9
well,generally try to instansiate your objects and then use them,in so that you don't get NullPointerException...for example:String[] fields = new String[line.length()];fields = line.split(",");
apanousisa at 2007-7-12 11:45:21 > top of Java-index,Java Essentials,New To Java...