我写了一个来查看、编辑和创建联系人。当我在模拟器中运行代码时,它允许我输入名称,但我无法切换到其他编辑文本并且模拟器冻结。即使我切换,我唯一能做的就是按下后退按钮。这是我的代码,你能帮我调试一下吗?我是android编程的新手,欢迎所有建议。
public class AddNewContact extends Activity implements OnClickListener {
Button Save;
EditText Newname, NewPersonalPhone, NewHomePhone, NewOfficePhone;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newcontact);
initialize();
}
private void initialize() {
// TODO Auto-generated method stub
Save = (Button) findViewById(R.id.bSaveContact);
Save.setOnClickListener(this);
Newname = (EditText) findViewById(R.id.newname);
Newname.setOnClickListener(this);
NewPersonalPhone = (EditText) findViewById(R.id.newpersonalphone);
NewPersonalPhone.setOnClickListener(this);
NewHomePhone = (EditText) findViewById(R.id.newhomephone);
NewHomePhone.setOnClickListener(this);
NewOfficePhone = (EditText) findViewById(R.id.newofficephone);
NewOfficePhone.setOnClickListener(this);
}
public void onClick(View v) {
boolean didItWork = true;
// TODO Auto-generated method stub
try {
String nname = Newname.getText().toString();
String npphone = NewPersonalPhone.getText().toString();
String nhphone = NewHomePhone.getText().toString();
String nophone = NewOfficePhone.getText().toString();
DBContact newentry = new DBContact(AddNewContact.this);
newentry.open();
newentry.newRow(nname, npphone, nhphone, nophone);
newentry.close();
} catch (Exception e) {
didItWork = false;
String error = e.toString();
Dialog display = new Dialog(this);
display.setTitle("ERROR");
TextView text = new TextView(this);
text.setText(error);
display.setContentView(text);
display.show();
} finally {
if (didItWork) {
Dialog display = new Dialog(this);
display.setTitle("CONTACT SAVED!");
TextView text = new TextView(this);
text.setText("Sucess");
display.setContentView(text);
display.show();
// startActivity(new Intent("CONTACTS.class"));
}
}
}
}
LOGCAT
09-26 02:58:35.518: E/WindowManager(1913): Activity com.example.contactlist.AddNewContact has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41236e28 that was originally added here
09-26 02:58:35.518: E/WindowManager(1913): android.view.WindowLeaked: Activity com.example.contactlist.AddNewContact has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41236e28 that was originally added here
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.Window$LocalWindowManager.addView(Window.java:547)
09-26 02:58:35.518: E/WindowManager(1913): at android.app.Dialog.show(Dialog.java:277)
09-26 02:58:35.518: E/WindowManager(1913): at com.example.contactlist.AddNewContact.onClick(AddNewContact.java:56)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.View.performClick(View.java:4084)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.View.onKeyUp(View.java:7669)
09-26 02:58:35.518: E/WindowManager(1913): at android.widget.TextView.onKeyUp(TextView.java:5382)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.View.dispatchKeyEvent(View.java:7086)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892)
09-26 02:58:35.518: E/WindowManager(1913): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369)
09-26 02:58:35.518: E/WindowManager(1913): at android.app.Activity.dispatchKeyEvent(Activity.java:2356)
09-26 02:58:35.518: E/WindowManager(1913): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.deliverKeyEvent(ViewRootImpl.java:3531)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3113)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
09-26 02:58:35.518: E/WindowManager(1913): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2930)
09-26 02:58:35.518: E/WindowManager(1913): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 02:58:35.518: E/WindowManager(1913): at android.os.Looper.loop(Looper.java:137)
09-26 02:58:35.518: E/WindowManager(1913): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 02:58:35.518: E/WindowManager(1913): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 02:58:35.518: E/WindowManager(1913): at java.lang.reflect.Method.invoke(Method.java:511)
09-26 02:58:35.518: E/WindowManager(1913): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 02:58:35.518: E/WindowManager(1913): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 02:58:35.518: E/WindowManager(1913): at dalvik.system.NativeStart.main(Native Method)