This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Incompatible types! Into array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Incompatible types! Into array." Watch "Incompatible types! Into array." New topic
Author

Incompatible types! Into array.

g Peshone
Ranch Hand

Joined: Oct 20, 2008
Posts: 44
How would I convert string into an object to I can inserted into array?
Thanks
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Originally posted by g Peshone:
How would I convert string into an object to I can inserted into array?


If you only want the name of the Body to be inserted into the Array you can use a String array instead of your SolBody type Array. Otherwise you could just insert the whole object into your array instead of the name.


[ October 22, 2008: Message edited by: Paul Yule ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

i.e.,

bodies[0] = sun;


[Jess in Action][AskingGoodQuestions]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Your array is declared to hold references to instances of SolBody, and a String is not a SolBody. It looks to me like you just want to add "sun" to the array, bodies[0] = sun;

(Also, it looks like "nameFor" is already a String, so calling toString() on nameFor isn't necessary.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
g Peshone
Ranch Hand

Joined: Oct 20, 2008
Posts: 44
Thanks, that works, I thought I could go thru with a generic �field� name but then I could not increment it in the next step to insert next name.
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Incompatible types! Into array.