I have an activity that shows some TextViews and EditTexts, as well as DatePickers and TimePickers. Now I am adding a Spinner, and its pretty much close to the bottom, just like my code is in the onCreate() for it. When I click on the Spinner, it pops open up, probably cuz its close to the bottom and there isn’t enough room. So I thought i’d test it out when it was on the top. But it failed. The error is:
06-20 15:31:28.802: E/AndroidRuntime(980): java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.zeroe/com.zeroe.AddEventActivity}:
java.lang.ClassCastException: android.widget.Spinner cannot be cast to
android.widget.Button
I don’t understand that, but from what I am guessing, the placement of the XML should follow the placement of the code. I am literally copy-and-pasting the xml code to the top, so I know I am not altering anything. So is this a rule, or am I making some sort of mistake? Thanks for your input in advance.
EDIT:
My Code Spinner spinner = (Spinner)findViewById(R.id.reminder_spinner);
Beware that when you change your layouts, sometimes Eclipse does not rebuild the resources and you are left with ids that do not match their XML declared Views. A full clean and rebuild should take care of it.