0

Line 33, all debug logs are fine. As u can see I even comented the method that is causing problems and it still crashesh.

MainActivity.java

 package com.example.hillsmatrixinverser;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    Math matrix;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText Text1 = (EditText) findViewById(R.id.a) ;
       final  EditText Text2 = (EditText) findViewById(R.id.b) ;
       final  EditText Text3 = (EditText) findViewById(R.id.c) ;
       final   EditText Text4 = (EditText) findViewById(R.id.d) ;
    //   final    EditText TextFinal = (EditText) findViewById(R.id.editText1) ;
        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //

                Log.d("TEXT1", Text1.getText().toString());
                Log.d("TEXT2", Text2.getText().toString());
                Log.d("TEXT3", Text3.getText().toString());
                Log.d("TEXT4", Text4.getText().toString());

               matrix.GetValues(Text1.getText().toString(), Text2.getText().toString(),
                       Text3.getText().toString(), Text4.getText().toString());
               // TextFinal.setText(matrix.Calculate());
            }
        });

    }





    }

class:

package com.example.hillsmatrixinverser;

import android.app.Application;

    public class Math {

        public int a;
        public int b;
        public int c;
        public int d;
        public void  GetValues(String a1, String b1, String c1, String d1){

               // Integer.parseInt(a1); 
            //   Integer.parseInt(b1);
           //   Integer.parseInt(c1);
             //  Integer.parseInt(d1); 


        }
        public String Calculate(){
            return Integer.toString(a+b+c+d);

        }
    }

Line causing problems:

matrix.GetValues(Text1.getText().toString(), Text2.getText().toString(),
                           Text3.getText().toString(), Text4.getText().toString());

1 Answer 1

4

You never initialize Math matrix;

So when you're trying to call your GetValues method on your matrix object, it throws the NPE.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm thanks, I just need some explenation. I just started learning and I came from cpp where doing something like that was ok.
@zarcel Then consider reading this, that will help you : docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html. Let me know, if after reading this, you don't understand something well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.