Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem with arrays and custom objects

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with arrays and custom objects

    Hi guys and gals,

    I'm quite new to Java, and am presently muddling my way through an instruction course. I have got to dealing with custom Objects and using these in arrays. As a little play, I decided to generate a few little snippets of code that generate a "Planet" object with some properties and randomly seeds these amongst an x/y grid. That was the plan anyway!

    What is actually happening is that the creation code is correctly generating the planet information, but when I pull it back it is not displaying a String associated with the relevant item in the array, but instead is returning the last String associated witht the last object in the array. I'm wondering if I have messed something up with the way that I have linked through, but I have been using "getters" and "setters" to modify the instance variables associated with the "planet" object, and so it should not have been possible to "overwrite" the instance variables, as they were set to private.

    I have zipped the files used - the Planet.java file contains the information relating to the "Planet" object, whilst the Universe.java contains the main() class. The TextIO file is just something I'm using for displaying to the standard output screen, rather than use the inbuilt functions in Java.
    Universe.zip

    Any help is greatly apreciated - I've lost a day on it as I've rewritten the code to try to get rid of this "feature", but it still exists.

    Thanks
    MB


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem with arrays and custom objects

    Can you make a small simple program that compiles and executes to show your problem instead of the zip file?
    when I pull it back it is not displaying a String
    What does "pull it back" mean?

    rather than use the inbuilt functions in Java.
    Why? That makes one more thing to debug.

Similar Threads

  1. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  2. Problem in generation of custom classes at web service client
    By vinod.pandey in forum Member Introductions
    Replies: 0
    Last Post: January 10th, 2011, 07:12 AM
  3. Custom Java stack class (with generics) problem
    By TBBucs in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 7th, 2010, 02:25 AM
  4. Arrays Of Objects?
    By MysticDeath in forum Object Oriented Programming
    Replies: 2
    Last Post: October 20th, 2009, 09:39 PM
  5. Throwing arrays as objects
    By Audemars in forum Collections and Generics
    Replies: 1
    Last Post: September 23rd, 2009, 06:29 PM

Tags for this Thread