嘿,我正在尝试这样做,以便一旦我单击一个按钮,它就会计算一些东西,然后将 EditText 更改为答案。当我点击按钮时,程序崩溃了!请帮助我,因为我是 Android 新手。
爪哇代码:
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));
}
}
这是我的 LogCat 内容:
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