Hello,
First of all I hope this is the right place! I am a bit of a newbie at Java and I am having a mental breakdown in my assignment. Hopefully a kind member can pin-point me in the right direction. To cut a long story short I require to create a 2D boolean array of height 5 and width 6, with a total number of letters displayed as 10. I have a utility class in which it encodes alphabetic characters and the space character into 2d boolean values. As a display, it will print "." for false values, and "O" for true values, creating a text representation.
My problem is that despite compiling the code with no errors, I receive a "Exception: line 2. java.lang.NullPointerException" error when I execute the commands
LEDDisplay led = new LEDDisplay(); led.display();
Here is my coding so far, please excuse the excess template code that I haven't deleted and edited after creating a new class
/** * Class LEDDisplay - write a description of the class here. * * @author (your name) * @version (a version number or a date) */ public class LEDDisplay { /* instance variables */ boolean[][] matrix; /* Private class constants */ public static int FONT_LETTER_HEIGHT = 5; public static int FONT_LETTER_WIDTH = 6; public static int LETTERS_PER_DISPLAY = 10; /** * Default constructor for objects of class LEDDisplay */ public LEDDisplay() { super(); boolean[][] matrix = new boolean[FONT_LETTER_HEIGHT][(FONT_LETTER_WIDTH * LETTERS_PER_DISPLAY)]; } /* instance methods */ /** * An instance method to print the table with '.' to represent the false and * 'O' to represent the true boolean values from the array */ public void display() { for(int j = 0; j < FONT_LETTER_HEIGHT; j++) { for(int i = 0; i < (FONT_LETTER_WIDTH * LETTERS_PER_DISPLAY); i++) { if (matrix[j][i]) { System.out.print('.'); } else { System.out.print('O'); } System.out.print(matrix); } System.out.println(); } System.out.println(); } }
Many thanks for your time