Does the placement of your Views in XML have to match your code in your Activity?

darti

New Member
I have an activity that shows some \[code\]TextView\[/code\]s and \[code\]EditText\[/code\]s, as well as \[code\]DatePicker\[/code\]s and \[code\]TimePicker\[/code\]s. Now I am adding a \[code\]Spinner\[/code\], and its pretty much close to the bottom, just like my code is in the \[code\]onCreate()\[/code\] 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:\[code\]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 toandroid.widget.Button\[/code\]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 \[code\]Spinner spinner = (Spinner)findViewById(R.id.reminder_spinner);\[/code\]
 
Back
Top