Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

iftekhar uddin
iftekhar uddin
4,194 Points

Exception in thread "main" java.lang.NullPointerException

Problem: I'm getting this error

Exception in thread "main" java.lang.NullPointerException
at com.teamtreehouse.model.SongBook.addSong(SongBook.java:14)
at Karaoke.main(Karaoke.java:14)

My Code

I have looked at SongBook.java line 14 and unless I'm blind it's exactly how it is with craig's code in the video "building the model"

thanks for taking the time reading and responding to my question. Much Appreciated.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

iftekhar;

In SongBook.java you have

public void SongBook()  {
   mSongs = new ArrayList<Song>();
}

Remove the void from that method, as in the videos, and your code works great. Remember that in Java constructors don't have explicit return types in their method signatures.

Happy coding,
Ken

iftekhar uddin
iftekhar uddin
4,194 Points

Oh my god I feel so stupid XD. I tunnel visioned on that line so much that I didn't even realize that constructor was messed up. Thanks =)

Ken Alger
Ken Alger
Treehouse Teacher

Don't feel stupid. That's part of the learning process.