Harder Challenge


For this challenge, I’ve decided to have both pickers inside a ViewSwitcher. When the dialog opens up, it shows the DatePicker, with a button that says: Switch to Time.
The ViewSwitcher seems pretty practical: you have showPrevious() and showNext() to alternate views (in this case, it alternates between datePicker and timePicker views).
Whatever has been modified by the user is update in the Crime Date.

However, when I tap on the Date button to fire up the dialog, I get an exception. I can’t find a solution. More importantly, I don’t know if the source of the error is in my code or in Android’s sdk (this question has been brought up in various stackoverflow threads).

Here’s my stack:
TypedArray.getLayoutDimension(int, String) line: 491
FrameLayout$LayoutParams(ViewGroup$LayoutParams).setBaseAttributes(TypedArray, int, int) line: 5614
FrameLayout$LayoutParams(ViewGroup$MarginLayoutParams).(Context, AttributeSet) line: 5756
FrameLayout$LayoutParams.(Context, AttributeSet) line: 610
ViewSwitcher(FrameLayout).generateLayoutParams(AttributeSet) line: 554
ViewSwitcher(FrameLayout).generateLayoutParams(AttributeSet) line: 56
PhoneLayoutInflater(LayoutInflater).parseInclude(XmlPullParser, View, AttributeSet) line: 820
PhoneLayoutInflater(LayoutInflater).rInflate(XmlPullParser, View, AttributeSet, boolean) line: 736
PhoneLayoutInflater(LayoutInflater).inflate(XmlPullParser, ViewGroup, boolean) line: 489
PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup, boolean) line: 396
PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup) line: 352
DatePickerFragment.onCreateDialog(Bundle) line: 64
DatePickerFragment(DialogFragment).getLayoutInflater(Bundle) line: 295
FragmentManagerImpl.moveToState(Fragment, int, int, int, boolean) line: 911
FragmentManagerImpl.moveToState(int, int, int, boolean) line: 1088
BackStackRecord.run() line: 682
FragmentManagerImpl.execPendingActions() line: 1444
FragmentManagerImpl$1.run() line: 429
Handler.handleCallback(Message) line: 725
FragmentActivity$1(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5041
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object…) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 793
ZygoteInit.main(String[]) line: 560
NativeStart.main(String[]) line: not available [native method]

Here’s my Dialog xml file:


<include layout="@layout/dialog_date" />

<include layout="@layout/dialog_time" />

My Date picker xml file:


    android:calendarViewShown="false" >



And my TimePicker xml file:


    android:layout_height="wrap_content" >

    android:text="@string/switch_to_date_label" />


Finally, I inflate this ViewSwitcher like so:

public Dialog onCreateDialog(Bundle savedInstanceState) { /*...*/ final ViewSwitcher vs = (ViewSwitcher)getActivity().getLayoutInflater().inflate(R.layout.dialog_viewswitcher, null); /*...*/ }

I am out of ways to debug this issue. Any hint is appreciated!


Did you look at the LogCat output? It will have the Exception info.


LogCat doesn’t seem to say much. I copied the whole output since the launch of the app.

LogCat output:

06-16 03:26:32.901: W/ActivityThread(14152): Application com.bignerdranch.android.criminalintent is waiting for the debugger on port 8100... 06-16 03:26:32.931: I/System.out(14152): Sending WAIT chunk 06-16 03:26:32.941: I/dalvikvm(14152): Debugger is active 06-16 03:26:33.131: I/System.out(14152): Debugger has connected 06-16 03:26:33.131: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:33.341: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:33.542: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:33.742: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:33.941: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:34.152: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:34.353: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:34.552: I/System.out(14152): waiting for debugger to settle... 06-16 03:26:34.752: I/System.out(14152): debugger has settled (1467) 06-16 03:26:35.532: D/dalvikvm(14152): GC_FOR_ALLOC freed 66K, 7% free 2700K/2888K, paused 27ms, total 39ms 06-16 03:26:35.532: I/dalvikvm-heap(14152): Grow heap (frag case) to 3.358MB for 635812-byte allocation 06-16 03:26:35.572: D/dalvikvm(14152): GC_FOR_ALLOC freed 3K, 6% free 3318K/3512K, paused 39ms, total 39ms 06-16 03:26:35.622: D/dalvikvm(14152): GC_CONCURRENT freed 0K, 6% free 3323K/3512K, paused 4ms+20ms, total 42ms 06-16 03:26:36.931: I/Choreographer(14152): Skipped 298 frames! The application may be doing too much work on its main thread. 06-16 03:26:36.991: D/gralloc_goldfish(14152): Emulator without GPU emulation detected. 06-16 03:26:37.542: I/Choreographer(14152): Skipped 106 frames! The application may be doing too much work on its main thread. 06-16 03:27:29.762: D/dalvikvm(14152): GC_CONCURRENT freed 90K, 6% free 3623K/3832K, paused 3ms+3ms, total 43ms 06-16 03:27:30.331: I/Choreographer(14152): Skipped 100 frames! The application may be doing too much work on its main thread. 06-16 03:27:32.271: I/Choreographer(14152): Skipped 55 frames! The application may be doing too much work on its main thread.

I just realized I didn’t mention in my original post that when I press “resume” on the debugger toolbar, twice, the dialog shows up…


Just a guess here as I am learning this for the first time:

It looks as though the trouble is with inflating the viewswitcher. Maybe you should try wrapping your two <include…/> lines into vertical linear layouts.


android:orientation=“vertical” >

android:orientation=“vertical” >

My reasoning for this is that the ViewSwitcher needs two nested ViewGroups to function properly. The include lines may not be seen as child ViewGroup objects in the eyes of the ViewSwitcher.

Just a shot in the dark here.


I haven’t tested code with your example, but another suggestion I’d have would be to wrap your ViewSwitcher in a FrameLayout. The problem appears to be with setting up its layout params. This case requires it to be inflated without a parent, which might be causing a problem - perhaps it’d get fixed with a parent.


Thank you for your replies. Also, I want to apologize for not being a nice forum citizen. I shouldn’t have let these posts unreplied for that long.

I will remember your solutions, but won’t be able to test them… In order to keep moving, I deleted the challenge part.

Again, thank you for your time.