Results 1 to 5 of 5
Thread: HashMap Null error
- 02-11-2012, 06:28 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 28
- Rep Power
- 0
HashMap Null error
Hi. I have a HashMap which maps a String to a JLabel:
But later on in the codes when I try to get the JLable via the HashMap, it gives me the "NullPointerException" exception error.Java Code:tileSlots.put("slot0", slot0);
Error at:
Any idea wats wrong?Java Code:JLabel x = tileSlots.get("slot"+i); print(x.getName());
P.S:- tileSlots is declared as public and the print line is where the error points to. The code where the error occurs is in a loop, thats why am using "i" variable.
- 02-11-2012, 06:36 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: HashMap Null error
The code looks fine. Perhaps you are using two different Maps (one local Map with the same name :D)?
- 02-11-2012, 06:41 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 28
- Rep Power
- 0
Re: HashMap Null error
I just checked and am not using a local map. The "tileSlots" var is in green as am using Netbeans as SDK. Would you like the whole IF statement if it might help? (thnx for the quick reply though
)
- 02-11-2012, 06:43 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: HashMap Null error
Yes, maybe a little bit more code would help.
- 02-11-2012, 06:45 PM #5
Member
- Join Date
- Jan 2012
- Posts
- 28
- Rep Power
- 0
Re: HashMap Null error
There:
Java Code:if (data.contains("Tile") && data.contains("L")) { dominogameServer.Tile[] tileSet = (dominogameServer.Tile[]) input; for(int i=0;i<tileSet.length;i++){ tiles.add(new Tile(tileSet[i].getTileNum())); // 'tiles' type is 'ArrayList' JLabel x = tileSlots.get("slot"+i); print(x.getName()); showIcon(x, tileSet[i].getTileNum()); } for (int i=0;i<tileSet.length;i++){ print("tile: " + tileSet[i].getTileNum()); } }Last edited by anoorally; 02-12-2012 at 09:56 AM.
Similar Threads
-
Null error Thread
By anoorally in forum New To JavaReplies: 3Last Post: 02-08-2012, 11:44 PM -
null pointer error help!!
By fakepics500 in forum New To JavaReplies: 1Last Post: 07-16-2011, 02:57 PM -
HashMap assignment and null pointer exception
By merik in forum New To JavaReplies: 2Last Post: 03-11-2011, 05:18 AM -
help with with my null error
By zhangster in forum New To JavaReplies: 3Last Post: 03-20-2010, 12:32 AM -
Null Error
By scoleman123 in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks