• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Incompatible types! Into array.

 
g Peshone
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I convert string into an object to I can inserted into array?
Thanks
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i.e.,

bodies[0] = sun;
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
g Peshone
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic