The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

NullPointerException error

Hi, my program reads out of a textfile containing about 20 hockey players. At the beginning of the program, the user is given the option to sort by name, rating, club or position. No matter what I press, I always get a nullpointerexception error. This never happened before and the program works fine on my friends computer, it also used to work fine on mine and then I randomly got this error. What do I do to fix this?

This is what is says in the bluej thingy

java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare (String.java:1217)
at java.lang.String$CaseInsensitiveComparator.compare (String.java:1211)
at java.lang.String.compareToIgnoreCase(String.java:1 258)
at FINAL.sort(FINAL.java:206)
at FINAL.options(FINAL.java:48)
at FINAL.main(FINAL.java:41)

Re: NullPointerException error

What do I do to fix this?

Your first need to post code, preferably an abbreviated version, which clearly demonstrates the problem. The stack trace you posted provides a lot of information but is meaningless without the context of the code that throws the exception.

Re: NullPointerException error

Thanks, it works now. i have another question, when I add a player to the database, it works fine. But when I try to remove a player from the database, it doesn't work. Another thing is, after I use the remove function, the other functions won't work anymore (for example, after using remove, i tried to sort the players by name, it didn't work because I got an array out of bounds error) Here is the code I use for adding players

Re: NullPointerException error

Please don't bump threads. I recommend you read the Welcome Announcements, in particular clause F. Moreover, you've provided very little information for us to help. "It doesn't work" could mean a million things. Describe the behavior you expect, and the behavior you receive (suggested reading: How To Ask Questions)