How to use an array in a class?
in
Programming Questions
•
2 years ago
Hi!
I am new to processing and Java. The following code gives the "NullPointerException" error (on line 9). The problem is that the array is not initialised.
- class TClass{
- int[][] A;
- void setup(){
- A = new int[10][10];
- }
- }
- void setup(){
- TClass TC = new TClass();
- TC.A[0][0] = 10;
- }
How can I use a 2d array in a class? Please note the following definition also gives error (constructor TClass not defined):
- class TClass{
- int[][] A;
- TClass(){
- A = new int[10][10];
- }
- }
1