I'm trying to pick time following this guide: http://developer.android.com/intl/es/guide/topics/ui/controls/pickers.html
But I'm getting this error:
01-11 19:37:58.513: E/AndroidRuntime(2419): FATAL EXCEPTION: main 01-11 19:37:58.513: E/AndroidRuntime(2419): java.lang.NullPointerException 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.app.DialogFragment.show(DialogFragment.java:228) 01-11 19:37:58.513: E/AndroidRuntime(2419): at iuAndroid.Informe$TimePickerFragment.showTimePickerDialog(Informe.java:126) 01-11 19:37:58.513: E/AndroidRuntime(2419): at iuAndroid.Informe$1.onClick(Informe.java:80) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.view.View.performClick(View.java:4240) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.view.View$PerformClick.run(View.java:17721) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.os.Handler.handleCallback(Handler.java:730) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.os.Handler.dispatchMessage(Handler.java:92) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.os.Looper.loop(Looper.java:137) 01-11 19:37:58.513: E/AndroidRuntime(2419): at android.app.ActivityThread.main(ActivityThread.java:5103) 01-11 19:37:58.513: E/AndroidRuntime(2419): at java.lang.reflect.Method.invokeNative(Native Method) 01-11 19:37:58.513: E/AndroidRuntime(2419): at java.lang.reflect.Method.invoke(Method.java:525) 01-11 19:37:58.513: E/AndroidRuntime(2419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 01-11 19:37:58.513: E/AndroidRuntime(2419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 01-11 19:37:58.513: E/AndroidRuntime(2419): at dalvik.system.NativeStart.main(Native Method)
My class timePicker:
public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
@Override
public void onTimeSet(final TimePicker view, final int hourOfDay, final int minute) {
// TODO Auto-generated method stub
}
public void showTimePickerDialog(final View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(), "timePicker");
}
}
When I do: newFragment.show(getFragmentManager(), "timePicker");
it returns a NullPointer..
And this is the part of my layout:
<TextView
android:id="@+id/from_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/from_name"/>
<Button
android:id="@+id/timeFrom"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:onClick="showTimePickerDialog"
style="@android:style/Widget.DeviceDefault.Light.Spinner"
/>
<TextView
android:id="@+id/to_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/to_name"/>
<Button
android:id="@+id/timeTo"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:onClick="showTimePickerDialog"
style="@android:style/Widget.DeviceDefault.Light.Spinner"
/>
iuAndroid.Informe$1.onClick()? Since you seem to be having a non-static factory-like methodshowTimePickerDialog()(you shouldn't), you're possibly calling it on an badly initialized object.