Я пытаюсь получить дату из указателя даты в диалоговом окне.Но происходит сбой с NullpointerExeption, и я не знаю почему .. Все остальное работает очень хорошо.Поэтому я публикую только соответствующий и написанный код для средства выбора даты.
Следующие коды:
В общедоступном классе я инициализировал средство выбора даты:
public class homework extends ListActivity {
DatePicker date_pick;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homework);
//Only some more code for managing database and some functions
}
/*** HERE ARE SOME FUNCTIONS AND CODE FOR CREATING THE CONTEXT MENU etc */
//What to do by clicking the "Hausaufgabe hinzufügen" button
private Button.OnClickListener add_hw = new Button.OnClickListener(){
public void onClick(View arg0) {
mDbHelper.open_database_rw();
String txt_insert_hw = insert_hw.getText().toString();
if(txt_insert_hw.equals("")){
doMessage("Keine Eingabe!");
}else{
final String INSERT_HW = "INSERT INTO tbl_homework ('hw') VALUES ('=> " + txt_insert_hw + "')";
db.execSQL(INSERT_HW);
insert_hw.setText("");
/***It's crashing here*/
String date_picker_message= (date_pick.getMonth()+1) +"/"+date_pick.getDayOfMonth()+"/"+date_pick.getYear();
/****/
fillData();
}
}};
//Code for dialog
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;;
switch(id) {
case ADD_HW_DIALOG:
dialog = new Dialog(homework.this);
dialog.setContentView(R.layout.customlayout_hw);
dialog.setTitle("Hausaufgabe hinzufügen");
date_pick= (DatePicker)findViewById(R.id.date_maturity);
break;
}
return dialog;
}
}
Код ОШИБКИ:
02-01 10:52:33.554: E/AndroidRuntime(230): Uncaught handler: thread main exiting due to uncaught exception
02-01 10:52:33.574: E/AndroidRuntime(230): java.lang.NullPointerException
02-01 10:52:33.574: E/AndroidRuntime(230): at test.marco.notenha.homework$1.onClick(homework.java:175)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.View.performClick(View.java:2364)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.View.onTouchEvent(View.java:4179)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.widget.TextView.onTouchEvent(TextView.java:6541)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.View.dispatchTouchEvent(View.java:3709)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-01 10:52:33.574: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
02-01 10:52:33.574: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.app.Dialog.dispatchTouchEvent(Dialog.java:643)
02-01 10:52:33.574: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.os.Looper.loop(Looper.java:123)
02-01 10:52:33.574: E/AndroidRuntime(230): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-01 10:52:33.574: E/AndroidRuntime(230): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 10:52:33.574: E/AndroidRuntime(230): at java.lang.reflect.Method.invoke(Method.java:521)
02-01 10:52:33.574: E/AndroidRuntime(230): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-01 10:52:33.574: E/AndroidRuntime(230): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-01 10:52:33.574: E/AndroidRuntime(230): at dalvik.system.NativeStart.main(Native Method)
02-01 10:52:33.604: I/dalvikvm(230): threadid=7: reacting to signal 3
02-01 10:52:33.604: E/dalvikvm(230): Unable to open stack trace file '/data/anr/traces.txt': Permission denied