shar iqbal
shar iqbal

Reputation: 23

Program crashing on click of a button Android Error

Hey I am trying to make it so that once I click a button, it calculates something and then changes the EditText to the answer. When I clicked the button, the program crashed! Please help me, as I am new to Android.

java code:

public class areacircle extends Activity {
TextView radiusTextView;
TextView areaTextView;
EditText radiusEditText;
Button areaButton;
EditText answerEditText;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
     setContentView(R.layout.areacircle);

     areaButton = (Button) findViewById(R.id.areaButton);
     answerEditText = (EditText) findViewById(R.id.answerEditText);
     radiusEditText = (EditText) findViewById(R.id.radiusEditText);


}

public void findarea(){
    answerEditText = (EditText) findViewById(R.id.answerEditText);
    double pi = Math.PI;
    double radius = Double.parseDouble(radiusEditText.getText().toString());
    double finalRadius = radius * radius *pi;

    answerEditText.setText(String.valueOf(finalRadius));


    }
}

Here is my LogCat contents:

08-28 14:41:06.558: E/Trace(823): error opening trace file: No such file or directory  (2)
08-28 14:41:09.876: D/gralloc_goldfish(823): Emulator without GPU emulation detected.
08-28 14:41:13.677: D/dalvikvm(823): GC_CONCURRENT freed 152K, 10% free 2613K/2896K, paused 5ms+6ms, total 507ms
08-28 14:41:13.677: I/Choreographer(823): Skipped 37 frames!  The application may be doing too much work on its main thread.
08-28 14:41:23.655: I/Choreographer(823): Skipped 31 frames!  The application may be doing too much work on its main thread.
08-28 14:41:30.986: D/AndroidRuntime(823): Shutting down VM
08-28 14:41:30.986: W/dalvikvm(823): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-28 14:41:31.035: E/AndroidRuntime(823): FATAL EXCEPTION: main
08-28 14:41:31.035: E/AndroidRuntime(823): java.lang.IllegalStateException: Could not  find a method findarea(View) in the activity class com.turnapps.essentials.areacircle for  onClick handler on view class android.widget.Button with id 'areaButton'
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.view.View$1.onClick(View.java:3586)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.view.View.performClick(View.java:4204)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.view.View$PerformClick.run(View.java:17355)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.os.Handler.handleCallback(Handler.java:725)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.os.Looper.loop(Looper.java:137)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.app.ActivityThread.main(ActivityThread.java:5041)
08-28 14:41:31.035: E/AndroidRuntime(823):  at java.lang.reflect.Method.invokeNative(Native Method)
08-28 14:41:31.035: E/AndroidRuntime(823):  at java.lang.reflect.Method.invoke(Method.java:511)
08-28 14:41:31.035: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-28 14:41:31.035: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-28 14:41:31.035: E/AndroidRuntime(823):  at dalvik.system.NativeStart.main(Native Method)
08-28 14:41:31.035: E/AndroidRuntime(823): Caused by: java.lang.NoSuchMethodException: findarea [class android.view.View]
08-28 14:41:31.035: E/AndroidRuntime(823):  at java.lang.Class.getConstructorOrMethod(Class.java:460)
08-28 14:41:31.035: E/AndroidRuntime(823):  at java.lang.Class.getMethod(Class.java:915)
08-28 14:41:31.035: E/AndroidRuntime(823):  at android.view.View$1.onClick(View.java:3579)
08-28 14:41:31.035: E/AndroidRuntime(823):  ... 11 more

Upvotes: 0

Views: 183

Answers (1)

Blackbelt
Blackbelt

Reputation: 157447

you have declared the onClick="findarea" propertis for your button. The correct signature takes a view as paramter. Change

public void findarea(){

with

public void findarea(View view){ 

Upvotes: 2

Related Questions