Results 1 to 4 of 4
Thread: Null Pointer Exception error
- 03-28-2010, 06:19 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 21
- Rep Power
- 0
Null Pointer Exception error
Hi, I have an assignment to make a voting program. The program compile fine, but I get the following runtime error:
Exception in thread "main" java.lang.NullPointerException
at BallotPaper.setPreference(BallotPaper.java:5)
at Test1.main(Test1.java:17)
Here's the relevant code:
Ballot Paper:
ArrayBasedMap is something we've been told to use. Put returns NULL if the entry is inserted correctly.Java Code:private ArrayBasedMap<Integer, Candidate> candPreference; public void setPreference( int pref, Candidate name ){ candPreference.put( pref, name ); }
Test1:
This might be something really simple, but I just can't figure it out.Java Code:Candidate Homer = new Candidate( "Homer", "FF" ); BallotPaper vote1 = new BallotPaper(); vote1.setPreference( 1, Homer );
Thanks in advance!Last edited by tfitz666; 03-28-2010 at 06:21 PM.
- 03-28-2010, 06:22 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
- 03-28-2010, 06:27 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 21
- Rep Power
- 0
*Face Palms* That's embarrassing:D Thanks!
- 03-28-2010, 07:20 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Null pointer Exception
By peiceonly in forum New To JavaReplies: 8Last Post: 09-05-2010, 06:48 PM -
Null Pointer Exception
By ScKaSx in forum New To JavaReplies: 1Last Post: 01-24-2009, 11:27 AM -
Null Pointer Exception
By Jacinth in forum New To JavaReplies: 4Last Post: 01-22-2009, 01:47 PM -
Null Pointer Exception
By demiser55 in forum New To JavaReplies: 1Last Post: 09-22-2008, 06:33 PM -
Null pointer exception error
By brownie_jedi in forum New To JavaReplies: 3Last Post: 03-15-2008, 06:27 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks