"this.elements" is null error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

"this.elements" is null error

Hello everyone. I do't know what to do in this situation tbh. I can not find where is the mistake. Can you help me ? public class cMatrix { private long [][] elements; private int row; private int col; /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here cMatrix m1 = new cMatrix(); m1.AssignRandom(); m1.printMatrix(); } public cMatrix(){ row = 10; col = 10; for (int i = 0; i < row; i++){ for (int j = 0; j < col; j++){ } } } public cMatrix(int row, int col){ this.row = row; this.col = col; } public void AssignRandom(){ Random randomNum = new Random(); for (int i = 0; i < row; i++){ for (int j = 0; j < col; j++){ long s; s = randomNum.nextLong(10000); } } } public void printMatrix(){ for (int i = 0; i < row; i++){ for (int j = 0; j < col; j++){ System.out.print(elements[i][j] + " "); } System.out.println(" "); } }

7th Nov 2021, 3:59 PM
Güneş Özkan
Güneş Özkan - avatar
2 Answers
+ 1
u didnt assign values to the elements
7th Nov 2021, 4:16 PM
ACE
ACE - avatar
0
Can you tell me how can I do it ? 【ACE】
7th Nov 2021, 4:33 PM
Güneş Özkan
Güneş Özkan - avatar