Could not execute method of Activity

12,350

Caused by: java.lang.NullPointerException, Usually, this means your staff is not initialized yet. Check the code around Line 63.

Share:
12,350
Exorcist
Author by

Exorcist

Updated on July 20, 2022

Comments

  • Exorcist
    Exorcist almost 2 years

    Well I have set of buttons and their onClick property is "click" like this android:onClick="click". I am running this in android 2.2

    Here's the click function in the main activity. This function is outside the onCreate method as expected.

    public void click(View v)
    {
        String s = et2.getText().toString();
    
        switch(v.getId())
        {
            case R.id.b0 :      
                if(s.length() == 1 && s.charAt(0) == '0')
                {  
                    et2.setText("0");
                    et1.setText("0");
                }
                else
                {
                    s = s + "0";
                    call(s);
                }
            break;
            //Other cases
        }
    }
    

    The problem is whenever I click any button, the app stops working (Force Close).

    Here's the Log:

    03-30 22:23:20.129: E/AndroidRuntime(1240): FATAL EXCEPTION: main 03-30 22:23:20.129: E/AndroidRuntime(1240): java.lang.IllegalStateException: Could not execute method of the activity 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.view.View$1.onClick(View.java:3044) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.view.View.performClick(View.java:3511) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.view.View$PerformClick.run(View.java:14105) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.os.Handler.handleCallback(Handler.java:605) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.os.Handler.dispatchMessage(Handler.java:92) 03-30 22:23:20.129: E/AndroidRuntime(1240): at
    android.os.Looper.loop(Looper.java:137) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.app.ActivityThread.main(ActivityThread.java:4424) 03-30 22:23:20.129: E/AndroidRuntime(1240): at java.lang.reflect.Method.invokeNative(Native Method) 03-30 22:23:20.129: E/AndroidRuntime(1240): at java.lang.reflect.Method.invoke(Method.java:511) 03-30 22:23:20.129: E/AndroidRuntime(1240): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 03-30 22:23:20.129: E/AndroidRuntime(1240): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 03-30 22:23:20.129: E/AndroidRuntime(1240): at dalvik.system.NativeStart.main(Native Method) 03-30 22:23:20.129: E/AndroidRuntime(1240): Caused by: java.lang.reflect.InvocationTargetException 03-30 22:23:20.129: E/AndroidRuntime(1240): at java.lang.reflect.Method.invokeNative(Native Method) 03-30 22:23:20.129: E/AndroidRuntime(1240): at java.lang.reflect.Method.invoke(Method.java:511) 03-30 22:23:20.129: E/AndroidRuntime(1240): at android.view.View$1.onClick(View.java:3039) 03-30 22:23:20.129: E/AndroidRuntime(1240): ... 11 more 03-30 22:23:20.129: E/AndroidRuntime(1240): Caused by: java.lang.NullPointerException 03-30 22:23:20.129: E/AndroidRuntime(1240): at yadav.sanjay.calculator.CalculatorActivity.click(CalculatorActivity.java:63)