Results 1 to 5 of 5
  1. #1
    HeavyTech is offline Member
    Join Date
    Jun 2014
    Posts
    30
    Rep Power
    0

    Default Adding Points objects into an Array

    Hi

    I am trying to add Point objects into an Array. But I having problems doing so. Can any one help?

    This is my code to read in data

    Java Code:
    public void readRoadMap(File road) {
    		try{
    			String line; 
    			BufferedReader br = new BufferedReader(new FileReader(road));
    
    			while((line = br.readLine()) !=null){
    				this.points.add(new Point(line));
    			}
    			br.close();
    		}
    		catch(Exception e){
    			e.printStackTrace();
    		}
    	}

    Now, in the Constructor I initialized the Array. Just like this

    Java Code:
    public RoadNetwork(File road){
    
    		BunchOfObjects<Point> points = new  BunchOfObjects<Point>();
    	
    		points.add(readRoadMap(road));
    	}
    I know I keep getting the error on
    Java Code:
     points.add(readRoadMap(road)
    Can any one help?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Adding Points objects into an Array

    What is a BunchOfObjects? The name suggests that it is a collection ... does it have an add( ... ) method?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Adding Points objects into an Array

    I keep getting the error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    9

    Default Re: Adding Points objects into an Array

    The method readRoadMap has a void return type so cannot be added to the array.
    Additionally, due to the redeclaration of points in the constructor, the constructor and the readRoadMap method are pointing to two different instances of points.

    Regards.

  5. #5
    HeavyTech is offline Member
    Join Date
    Jun 2014
    Posts
    30
    Rep Power
    0

    Default Re: Adding Points objects into an Array

    Thank you for the replies!
    Yes, I was able to correct my problems. My method was supposed to return an Array.
    and finally I did

    Java Code:
     this.points = readRoadMap(road, points);
    That seem to do the trick. I tested and works. Thanks again!

Similar Threads

  1. Replies: 3
    Last Post: 07-31-2014, 09:47 AM
  2. How to create Graph of points from array
    By enk1du in forum New To Java
    Replies: 6
    Last Post: 11-21-2012, 09:39 AM
  3. Replies: 6
    Last Post: 09-05-2011, 01:25 PM
  4. Replies: 2
    Last Post: 08-18-2011, 09:36 PM
  5. Replies: 1
    Last Post: 05-04-2010, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •