![]() |
|
[Java] NullPointerException - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] NullPointerException (/showthread.php?tid=5519589) |
NullPointerException - Mohinder - Jan 10, 2017 Hi, I'm creating a assignment for school. I'm getting this NullPointerException error and I don't know to solve it. Code Exception in thread "main" java.lang.NullPointerExceptionThe exact error I get. So the assignment is basically a password creator for a suitcase. The password will be something like AA0 or DZ1. This is the complete code of the Kofferslot.java file: Code package kofferslot;And the main file, where I create the object: Code package kofferslot;I've tryed to initialise the array before the constructor, with; Code package kofferslot;And I tryed this: Code public class Kofferslot {But both solutions I tryed won't work. I hope someone can help me out in here. * - Khamul - Jan 10, 2017 Where is 'Letter' defined? Shouldn't you be using 'char[]' instead of 'Letter[]'? Unless 'Letter' is some wrapper you've made for a char? Try something like this: Code private Letter[] letterlijst;* - Mohinder - Jan 10, 2017 (Jan 10, 2017 07:54 AM)ɴᴀᴢɢᴜʟ Wrote: Where is 'Letter' defined? Shouldn't you be using 'char[]' instead of 'Letter[]'? Unless 'Letter' is some wrapper you've made for a char? I will show you the Letter.java file: Code package kofferslot;* - Maxie - Jan 10, 2017 It seems like you are missing a proper constructor for the kofferslot, I might however be misstaken. * - 3clipse - Jan 10, 2017 You never actually allocate the array before setting anything in it, so you might want to do that What you have: Code public Kofferslot() {What you should have: Code public Kofferslot() {* - Khamul - Jan 10, 2017 (Jan 10, 2017 10:47 AM)Wiz0rd Wrote: You never actually allocate the array before setting anything in it, so you might want to do that You might want to read the OP * - Maxie - Jan 10, 2017 Hey! Looking at these two ^ posts over, I am missing the initation of the array. Put "()" after the [2]. * - 3clipse - Jan 10, 2017 (Jan 10, 2017 11:02 AM)ɴᴀᴢɢᴜʟ Wrote: You might want to read the OP lmao. That's literally the only thing that could be null on that line, so no matter what he needs to do it. (Jan 10, 2017 11:05 AM)Maxie Wrote: Hey! Looking at these two ^ posts over, I am missing the initation of the array. Put "()" after the [2]. No. |