0

So I am creating a 2x2 and 3x3 matrix solver. When testing the 3x3 matrices I encountered a null pointer error. I tried to figure out what is causing the error but couldn't any help would be really appreciated.

The error

12-03 10:08:37.363: E/AndroidRuntime(1467): FATAL EXCEPTION: main
12-03 10:08:37.363: E/AndroidRuntime(1467): java.lang.NullPointerException
12-03 10:08:37.363: E/AndroidRuntime(1467):     at com.uzusoft.matrixmaster.M15$1.onClick(M15.java:86)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.view.View.performClick(View.java:4240)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.view.View$PerformClick.run(View.java:17721)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.os.Handler.handleCallback(Handler.java:730)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.os.Looper.loop(Looper.java:137)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at android.app.ActivityThread.main(ActivityThread.java:5103)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invokeNative(Native Method)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invoke(Method.java:525)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-03 10:08:37.363: E/AndroidRuntime(1467):     at dalvik.system.NativeStart.main(Native Method)

and this is the code for M15.java:

public class M15 extends Activity {
    EditText a1text;
    EditText b1text;
    EditText c1text;
    EditText d1text;
    EditText e1text;
    EditText f1text;
    EditText g1text;
    EditText h1text;
    EditText i1text;
    TextView aR;
    TextView bR;
    TextView cR;
    TextView dR;
    TextView eR;
    TextView fR;
    TextView gR;
    TextView hR;
    TextView iR;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.matrix15); 

        a1text = (EditText) findViewById(R.id.EditText01);
        b1text = (EditText) findViewById(R.id.EditText02);
        c1text = (EditText) findViewById(R.id.EditText03);
        d1text = (EditText) findViewById(R.id.EditText04);
        e1text = (EditText) findViewById(R.id.EditText05);
        f1text = (EditText) findViewById(R.id.EditText06);
        g1text = (EditText) findViewById(R.id.EditText07);
        h1text = (EditText) findViewById(R.id.EditText08);
        i1text = (EditText) findViewById(R.id.EditText09);

        aR = (TextView) findViewById(R.id.textView1);
        bR = (TextView) findViewById(R.id.textView2);
        cR = (TextView) findViewById(R.id.textView3);
        dR = (TextView) findViewById(R.id.textView4);
        eR = (TextView) findViewById(R.id.textView5);
        hR = (TextView) findViewById(R.id.textView6);
        gR = (TextView) findViewById(R.id.textView7);
        hR = (TextView) findViewById(R.id.textView8);
        iR = (TextView) findViewById(R.id.textView9);
        Button button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            float a = Float.parseFloat(a1text.getText().toString());
            float b = Float.parseFloat(b1text.getText().toString());
            float c = Float.parseFloat(c1text.getText().toString());
            float d = Float.parseFloat(d1text.getText().toString());
            float e = Float.parseFloat(e1text.getText().toString());
            float f = Float.parseFloat(f1text.getText().toString());
            float g = Float.parseFloat(g1text.getText().toString());
            float h = Float.parseFloat(h1text.getText().toString());
            float i = Float.parseFloat(i1text.getText().toString());

            aR.setText(String.valueOf( -1*a ));
            bR.setText(String.valueOf( -1*b ));
            cR.setText(String.valueOf( -1*c ));
            dR.setText(String.valueOf( -1*d ));
            eR.setText(String.valueOf( -1*e ));
            fR.setText(String.valueOf( -1*f ));
            gR.setText(String.valueOf( -1*g ));
            hR.setText(String.valueOf( -1*h ));
            iR.setText(String.valueOf( -1*i ));
            }
        });
    }
}

Ok this was solved

That1Guy
  • 7,075
  • 4
  • 47
  • 59
Yousef Haraga
  • 121
  • 1
  • 1
  • 5

5 Answers5

1

I think you have forgotten to initialize fR

And you are accessing it fR.setText(String.valueOf( -1*f ));

Robin
  • 10,052
  • 6
  • 31
  • 52
0

Try aR.setText("" + String.valueOf( -1*a ));

Looking Forward
  • 3,579
  • 8
  • 45
  • 65
0

Try this.. you forget to initilize fR

fR = (TextView) findViewById(R.id.textView6);
Hariharan
  • 24,741
  • 6
  • 50
  • 54
0

You had init two times this TextView and forgot to init fR

    hR = (TextView) findViewById(R.id.textView6);
    gR = (TextView) findViewById(R.id.textView7);
    hR = (TextView) findViewById(R.id.textView8);

Init fR TextView

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44
0

You forgot to initialize fR. Replace fR = (TextView) findViewById(R.id.textView6); with hR = (TextView) findViewById(R.id.textView6); which is immediately after eR.

Sayeed
  • 11
  • 2