This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Android and the fly likes Tring to do a spinner and i am getting errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Tring to do a spinner and i am getting errors" Watch "Tring to do a spinner and i am getting errors" New topic
Author

Tring to do a spinner and i am getting errors

jawann jefferson
Greenhorn

Joined: Mar 06, 2012
Posts: 6
I am trying to do a spinner but i keep getting errors in my code. I followed the tutorials and tried to fit it to my needs but it doesn't seem to be working. I think the problems lies in the fact i'm not sure how to code these views if they are not in an activity all by themselves. Most tutorials have them in a single activity. But i am coding for a tablet and the exist within a fragment. Those are just my thoughts and here is the errors:

The method onCreate(Bundle) of type PatientFormFragment.NewPatientTask.GenderSpinner must override a superclass method from the "public void onCreate(Bundle savedInstanceState)"


The method onCreate(Bundle) is undefined for the type View for super.onCeate(savedInstanceState)



thats just the code for the spinner...if you need i can post the code for the whole fragment...but it is very long. I ask that you please be patient with me. I'm new and been working on these problems for over 2 months and have been kicked off other various help sites because my questions weren't good enough. But i find it hard to form correct questions when i'm not sure what the real problems are.
thanks
jj
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
onCreate is a method in Activity, not in View. In a View, you can get the Activity by casting the Context object that gets passed into the constructor.
jawann jefferson
Greenhorn

Joined: Mar 06, 2012
Posts: 6
Is this what you mean by casting Context with Activity:


i am still getting the same error... eclipse is asking me to remove the "@Override"
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Again: onCreate is a method of Activity, not View. It has no place in this class.

If you want to use the Activity object, the code would look something like this:



It sounds a bit as if you do not fully understand how Views interact with the main Activity (or other Activities, there can be several in an app).
jawann jefferson
Greenhorn

Joined: Mar 06, 2012
Posts: 6
My next question is do i need to use onCreate since its already used in the fragment? and just write code on how the spinner is supposed to work?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Every subclass of Activity has an onCreate method, but not subclasses of View.
jawann jefferson
Greenhorn

Joined: Mar 06, 2012
Posts: 6
Ok here's my new code. I deleted all that onCreate stuff cause i didn't need it but now i'm getting a new error


for GenderSpinner(this); i'm getting "Syntax error on token "this", ( expected after this token". Not sure why. I tried R.layout.patientformfragment (name of fragment it is in) and got the same error. I also tried admissionshome (name of activity it is in) and still got the same error
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tring to do a spinner and i am getting errors