I need to pass the string curDate between NewDateFragment and NewEventFrament, i see many peoples using Bundle, but using these i still having NullPointerException.
I transform the CalendarView to one string named curDate.
public class NewDateFragment extends Fragment {
public String curDate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_newdate,
container, false);
CalendarView calendar = (CalendarView) view.findViewById(R.id.calendarView);
//sets the listener to be notified upon selected date change.
calendar.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
curDate = day + "/" + month + "/" + year;
NewDateFragment fragment = new NewDateFragment();
Bundle bundle = new Bundle();
bundle.putString("date", curDate);
fragment.setArguments(bundle);
Log.d("Current Date:", curDate);
}
});
}
public class NewEventFragment extends Fragment {
// relative code inside onCreateView
Bundle b = getActivity().getIntent().getExtras();
final String dDate = b.getString("date");
}
My Logcat:
10-08 18:34:49.036 10293-10293/com.org.feedme.cisvmeeting.activities W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41640d88) 10-08 18:34:49.056 10293-10293/com.org.feedme.cisvmeeting.activities E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.org.feedme.cisvmeeting.activities, PID: 10293 java.lang.NullPointerException at com.org.feedme.fragments.NewEventFragment.attemptCreate(NewEventFragment.java:116) at com.org.feedme.fragments.NewEventFragment$1.onClick(NewEventFragment.java:61) at android.view.View.performClick(View.java:4569) at android.view.View$PerformClick.run(View.java:18570) at android.os.Handler.handleCallback(Handler.java:743) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5212) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) at dalvik.system.NativeStart.main(Native Method)
Thanks for all the help!