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: Java exception "result already defined"

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Java exception "result already defined"

    all i want to do is change the value of 'result' in a method call........ i'm getting 'result already defined' when compiling this code..
    thanks!

    class Bool
    {
    public static void main (String[] args)
    {
     
    boolean result = false;
    System.out.println("The boolean is before call " + result);
     
    ChangeBool(result);
    System.out.println("The boolean returned after call to method " + result);
    }
    public static boolean ChangeBool(boolean result)
        {
            boolean result = true;
            System.out.println("Change boolean value, result is " + result + " in method");
                 return result;
        }
    }


  2. #2
    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: simple change to a boolean value in a method call help...

    Hello rptech. Welcome to the Java Programming Forums

    You are getting this error because you are setting the variable 'result' twice.

    You only have to make a very small change:

    class Bool {
     
        public static void main(String[] args) {
     
            boolean result = false;
            System.out.println("The boolean is before call " + result);
     
            ChangeBool(result);
            System.out.println("The boolean returned after call to method "
                    + result);
        }
     
        public static boolean ChangeBool(boolean result) {
     
            [B]result = true;[/B]
            System.out.println("Change boolean value, result is " + result + " in method");
            return result;
        }
    }
    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.

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: simple change to a boolean value in a method call help...

    thank you for the quick response.... i'm new to java and getting the syntax is a bit tricky.... Thanks !!

  4. #4
    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: simple change to a boolean value in a method call help...

    No problem rptech,

    It was a very small mistake. I'm glad I could help.

    Please can you mark this thread as solved. (Check the link in my signature)

    Thank you.
    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. How to Write a simple XMPP (Jabber) client using the Smack API
    By JavaPF in forum Java Networking Tutorials
    Replies: 35
    Last Post: August 5th, 2014, 12:59 AM
  2. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM
  3. Java operaton on boolean varibles
    By big_c in forum Java Theory & Questions
    Replies: 5
    Last Post: May 12th, 2009, 04:40 AM
  4. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM
  5. Java program to write game
    By GrosslyMisinformed in forum Paid Java Projects
    Replies: 3
    Last Post: January 27th, 2009, 03:33 PM