et2.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
et2 = (EditText) findViewById(R.id.editText2);
area = Math.PI * radius * radius;
String name = Double.toString(area);
et2.setText(name);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
01-31 19:05:01.346:D / AndroidRuntime(650):关闭VM 01-31 19:05:01.346:W / dalvikvm(650):threadid = 1:线程退出未捕获异常(组= 0x40015560) 01-31 19:05:01.366:E / AndroidRuntime(650):致命异常:主要 01-31 19:05:01.366:E / AndroidRuntime(650):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.zlistactivity / com.example.zlistactivity.MainActivity}:java.lang.NumberFormatException: 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.os.Handler.dispatchMessage(Handler.java:99) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.os.Looper.loop(Looper.java:123) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread.main(ActivityThread.java:3683) 01-31 19:05:01.366:E / AndroidRuntime(650):at java.lang.reflect.Method.invokeNative(Native Method) 01-31 19:05:01.366:E / AndroidRuntime(650):at java.lang.reflect.Method.invoke(Method.java:507) 01-31 19:05:01.366:E / AndroidRuntime(650):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 01-31 19:05:01.366:E / AndroidRuntime(650):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-31 19:05:01.366:E / AndroidRuntime(650):at dalvik.system.NativeStart.main(Native Method) 01-31 19:05:01.366:E / AndroidRuntime(650):引起:java.lang.NumberFormatException: 01-31 19:05:01.366:E / AndroidRuntime(650):at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267) 01-31 19:05:01.366:E / AndroidRuntime(650):at java.lang.Double.parseDouble(Double.java:318) 01-31 19:05:01.366:E / AndroidRuntime(650):at java.lang.Double.valueOf(Double.java:356) 01-31 19:05:01.366:E / AndroidRuntime(650):at com.example.zlistactivity.MainActivity.onCreate(MainActivity.java:22) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-31 19:05:01.366:E / AndroidRuntime(650):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 01-31 19:05:01.366:E / AndroidRuntime(650):... 11更多 01-31 19:05:05.156:I / Process(650):发送信号。 PID:650 SIG:9
答案 0 :(得分:0)
在文本更改侦听器之前声明您的编辑文本:
et2 = (EditText) findViewById(R.id.editText2); et2.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count){ // TODO Auto-generated method stub area = Math.PI * radius * radius; String name = Double.toString(area); et2.setText(name); }