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

Thread: Retrived data is showing null string

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Retrived data is showing null string

    I am setting data as follows:
    currentRoom.setExits(null,theatre,pub.office)
    But getExit returns garbage values for last three
    routines re below:

     public Room getExit(String direction)
        {
     
            if (direction=="north") {
                return northExit;
            }
            if (direction=="east"){
                return eastExit;
            }
            if (direction=="south"){
                return southExit;
            }
            if (direction=="west"){
                return westExit;
            }
            return null;
        }
     
        public void setExits(Room north, Room east, Room south, Room west) 
        {
            if(north != null)
                northExit = north;
            if(east != null)
                eastExit = east;
            if(south != null)
                southExit = south;
            if(west != null)
                westExit = west;
        }


  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: Retrived data is showing null string

    But getExit returns garbage values
    Please copy and paste here the output that is shown.

    Use the equals() method when comparing the contents of String objects.
    The == operator is for primitives (or for testing if two object references point to the same object)

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Retrived data is showing null string

    Quote Originally Posted by Norm View Post
    The == operator is for primitives (or for testing if two object references point to the same object)
    Please see == operator or equals() method
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. [SOLVED] Confused about string that I think shouldn't be null
    By mjpam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2011, 11:08 PM
  2. Need something like a "Hashtable<String[], Integer>" kind of data type @@
    By Albretch Mueller in forum Java Theory & Questions
    Replies: 2
    Last Post: November 27th, 2010, 10:24 PM
  3. showMessageDialog is not showing!
    By jonathan920 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2010, 04:14 AM
  4. showing page
    By ighor10 in forum Java Theory & Questions
    Replies: 1
    Last Post: August 26th, 2010, 08:52 AM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM