-6
public void doMatrix(){
    double[][] arrayA = {{a11,a12,a13,a14},{a21,a22,a23,a24},{a31,a32,a33,a34},{a41,a42,a43,a44}};      
    double[][] arrayB = {{b1},{b2},{b3},{b4}};

    RealMatrix matrixA = MatrixUtils.createRealMatrix(arrayA);
    RealMatrix matrixB = MatrixUtils.createRealMatrix(arrayB);
    RealMatrix matrixInvA = new LUDecomposition(matrixA).getSolver().getInverse();
    RealMatrix matrixAmp = matrixInvA.multiply(matrixB);
    tryit = arrayA[2][2];

    }

The Value of tryit continues to return null when placed in a text box in my android main activity. Am I accessing the array wrong?.

Aritz
  • 30,971
  • 16
  • 136
  • 217

3 Answers3

5

I'm afraid that you are confused.

If arrayA is declared to have type double[][] then it is impossible for arrayA[2][2] to be null.

The type of arrayA[2][2] is double, and null is not a member of that type. Not ever. The null value is only valid for reference types, and double is a primitive type, not a reference type.

Either the program is not as you are describing it, or something else is causing a different value to be placed into the text box.


(Now if arrayA was declared to be a Double[][], it would be a different matter.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
3

the code will work fine unless you have initialised all the variables. tryit maybe returning null as it is not initialised with a value.

Abinash Sinha
  • 840
  • 6
  • 18
1

There is no issue in the syntax for accessing the array. arrayA[2][2] will return the value of the variable a33.You are getting null because probably the value of the variable a33 is null.

MansoorShaikh
  • 913
  • 1
  • 6
  • 19