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 4 of 4

Thread: Simple Question (I Think...?)

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

    Default Simple Question (I Think...?)

    Okay so this is probably really simple, but I am trying to make one class called builder create a copy of another class called house, and then return it to my main function.

    public House buildHouse()
    {
    House h1 = new House();
    return h1;
    }

    That is currently the code for the function.

    My problem is that while i am returning house h1 to the main function, my next functions in my main function are supposed to interact with this house, and i am getting errors as if the code cannot find house h1. It doesn't seem complicated and I'm almost positive it isn't but I would really appreciate any help.


  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Question (I Think...?)

    I'm sorry i didn't mean a copy of the class house, I meant I wanted to create an object of the house class and then return it to my main class, a bit new to java and I didn't think through my terminology before posting.

  3. #3
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Simple Question (I Think...?)

    Post your main method, as the syntax you've used for your buildHouse is correct.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple Question (I Think...?)

    //	
     
    b1.buildHouse();
     
    h1.setOccupant(b1);
    System.out.println(h1.getOccupant());

    the error that comes up is

    h1 cannot be resolved

    I know all of my functions work correctly because if I create a House object in the main function all of it works fine. It's just pulling this house out of another function that is giving me trouble.

Similar Threads

  1. Simple Question (hopefully)
    By KILL3RTACO in forum Java Theory & Questions
    Replies: 2
    Last Post: October 11th, 2011, 09:18 PM
  2. Simple I/O Question...well could be simple for you?
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 30th, 2011, 06:44 AM
  3. Help with a simple question
    By allea in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 28th, 2011, 07:46 AM
  4. Just a simple question
    By newbie in forum Java Theory & Questions
    Replies: 10
    Last Post: December 6th, 2010, 08:19 PM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM