File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 24187
    
  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
 
Don't get me started about those stupid light bulbs.
 
subject: Incompatible types! Into array.