我正在尝试从单击“保存”按钮的弹出窗口中获取文本字段值。但它正在抛出错误。
代码 :-
final Button btn_ContactDetails = (Button)findViewById(R.id.btn_ContactDetails);
btn_ContactDetails.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0) {
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.contactdetails, null, true);
final PopupWindow popUp = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
popUp.setBackgroundDrawable(new BitmapDrawable());
popUp.setOutsideTouchable(true);
popUp.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popUp.dismiss();
return true;
}
return false;
}
});
Button btnDismiss = (Button)layout.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
popUp.dismiss();
}
});
//On click Save - Contact Details
Button btn_Save_ContactDetails = (Button)layout.findViewById(R.id.btn_Save_ContactDetails);
btn_Save_ContactDetails.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
EditText mEdit, sEdit;
mEdit = (EditText)findViewById(R.id.txt_HouseNameNumber);
sEdit = (EditText)findViewById(R.id.txt_Address1);
sEdit.setText(mEdit.getText().toString());//THIS LINE IS THROWING ERROR
popUp.dismiss();
}
});
popUp.showAtLocation(layout, Gravity.CENTER, 0, 0);
}
});
错误 :-
06-12 03:21:37.828: E/AndroidRuntime(518): FATAL EXCEPTION: main
06-12 03:21:37.828: E/AndroidRuntime(518): java.lang.NullPointerException
06-12 03:21:37.828: E/AndroidRuntime(518): at sai.om.SaiActivity$3$3.onClick(SaiActivity.java:171)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.view.View.performClick(View.java:2408)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.view.View$PerformClick.run(View.java:8816)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.os.Handler.handleCallback(Handler.java:587)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.os.Looper.loop(Looper.java:123)
06-12 03:21:37.828: E/AndroidRuntime(518): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-12 03:21:37.828: E/AndroidRuntime(518): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 03:21:37.828: E/AndroidRuntime(518): at java.lang.reflect.Method.invoke(Method.java:521)
06-12 03:21:37.828: E/AndroidRuntime(518): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-12 03:21:37.828: E/AndroidRuntime(518): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-12 03:21:37.828: E/AndroidRuntime(518): at dalvik.system.NativeStart.main(Native Method)
谁能帮我找出我在这里做错了什么?我已经为投线错误提供了评论。