0

My calculator app error msg

I tried looking online but I only just started learning about Android Studio and the information given is too abstract.

Can someone translate this to English please?

Alright so I tried a couple things and now this is my issue... AnotherNullPointer

This method seems to be my problem. Line 194 is the content of my "else".

private void compute(){
        if(!Float.isNaN(value1)){
            value2 = Float.parseFloat(resultView.getText().toString());
            switch(Action){
                case Addition:
                    value1 = value1 + value2;
                    break;
                case Subtraction:
                    value1 = value1 - value2;
                    break;
                case Multiply:
                    value1 = value1 * value2;
                    break;
                case Divide:
                    value1 = value1 / value2;
                    break;
                case Eq:
                    break;
            }
        }
        else{
            value1 = Float.parseFloat(resultView.getText().toString());
        }
    }

1 Answers1

0

You are getting a null pointer exception, which means that you are trying to reference something that is null - it often means that you didn't instantiate an instance of a variable before you reference it. If you want the in-depth explanation, reference this Stackoverflow post: What is a NullPointerException, and how do I fix it?

This can be challenging to understand for someone who is learning Java/Android development, but that post should help.

In looking at the image you posted, the error is on line 194; therefore, your resultView is likely null.

To prove this to yourself, try setting a breakpoint in Android Studio on that line and debug it, and watch the resultView variable to confirm that it is null.

Additional comment: I just saw your first image, where you are setting resultView to a TextView. (Note that Android Studio no longer requires you to cast your TextView - on line 39 you can delete (TextView).) Then, make sure that you set that TextView to something within your code, or it will remain null, giving you the NPE error.

shagberg
  • 2,427
  • 1
  • 12
  • 23