Cannot use CharSequence or toString() for retrieved Date

#1

'm going through the Big Nerd Ranch Guide Android development 2nd edition and I’m currently on the CriminalIntent app. I’m following the tutorial step by step but there seems to be a bug that developed perhaps due to updates released after the book. I’m trying to retrieve my Date value and set it as text to my button.

The book suggests that I do this: mDateButton.setText(mCrime.getDate().toString());

I did that and also tried to wrap it in CharSequence as well like this mDateButton.setText((CharSequence) mCrime.getDate());, which was suggested when I hit alt-enter. In either case, this is what I’m getting from the stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jadecondos.criminalintent/com.example.jadecondos.criminalintent.CrimeActivity}: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.CharSequence at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.CharSequence at com.example.jadecondos.criminalintent.CrimeFragment.onCreateView(CrimeFragment.java:54)

I tried going through the book if I missed something but no. I couldn’t find relevant questions on StackOverFlow either. I appreciate all help.

Thanks.