我一直在關注這個this tutorial創建日期選擇器,但設置edit_text的價值時,我一直有一個NullPointerException,在這裏我的代碼的某些部分:NullPointerException異常:安卓EDITTEXT
// Update demo edittext when the "OK" button is clicked
((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.clearFocus();
// TODO Auto-generated method stub
String result_string = mDateTimePicker.getMonth()
+ "/"
+ String.valueOf(mDateTimePicker.getDay())
+ "/"
+ String.valueOf(mDateTimePicker.getYear())
+ " "
+ String.valueOf(mDateTimePicker.getHour())
+ ":"
+ String.valueOf(mDateTimePicker
.getMinute());
edit_text.setText(result_string);
mDateTimeDialog.dismiss();
}
這裏我聲明edit_text:
EditText edit_text ;
static final int DATE_DIALOG_ID = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.newcase, container,
false);
// final View formView = inflater.inflate(R.layout.mform,container,
// false);
final LinearLayout formbis = (LinearLayout) rootView
.findViewById(R.id.formbis);
/*
*
* ****************
*/
EditText edit_text = (EditText) rootView.findViewById(R.id.edittext1);
....
但edit_text的初始化似乎是'未使用'。
所有這些都在一個片段內。
thaaaaaaaaaaaaaaaaaaaaaaaaaaks it worked ^^ – kyokotsu