Announcement

Collapse
No announcement yet.

Java quickie

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java quickie

    can someone tell me why passing this boolean argument:

    ballThread[i] = new Thread(new BallThread (ballArray [i], even)

    to this:

    public BallThread (Ball b, boolean e)

    causes an error? it compiles fine without the boolean, all the variables are declared etc

    even is just a boolean value based on whether an object in a thread is odd or even

    cheers

  • #2
    Are you sure that boolean even=true; ?

    Comment


    • #3
      What exactly is the error when you try to compile it?
      I'm building a wagon! On some other part of the internets, obviously (but not that other site).

      Comment


      • #4
        thanks for responding, i'm still finding my feet with this, in answer to your questions

        even = ((i %2) ==0);

        that gives true or false?

        the error is: 'constructor BallThread (Ball, boolean) not found in class .......'

        as soon as i stop passing the boolean argument the program complies ok

        thanks

        Comment


        • #5
          Thought so.

          You need a constructor BallThread (Ball, boolean) in the BallThread class that instanciates a BallThread object.

          In other words, find the BallThread (Ball) object, copy the whole "function" and paste it below, then add a boolean functionality.

          To explain what I mean, this is a quick demonstration.
          Code:
             BallThread( Ball b )
             {
                //This is your original function
                this.ball = b;
             }
          
             BallThread( Ball b, boolean e )
             {
                //This is the new one you create
                this.ball = b;
                this.even = e;
             }
          Hope this helps.
          I'm building a wagon! On some other part of the internets, obviously (but not that other site).

          Comment


          • #6
            many thanks Skanky, thats exacty what i needed! i was on the crest of a wave being able to tell if a number was odd or even!

            even = ((i %2) ==0); // in one line as well!!!

            line, then that error came up.

            i still don't understand why i need the line 'even=e' before i use it, 'e' is passed to the constructor why can't i use it 'as-is'

            thanks

            Comment


            • #7
              That was just for demonstration purposes. In my example, the object stores that value for later use. For your program, you may use it when you initiate the object or store it too - what you need to do with it depends very much on what your program is doing and, well, what you need that value for.

              Basically, if you don't need to store the value, then you don't need that line.
              I'm building a wagon! On some other part of the internets, obviously (but not that other site).

              Comment


              • #8
                gotcha! thats what i couldn't understand

                thanks again

                Comment


                • #9
                  Originally posted by reds4ever
                  new BallThread (ballArray [i], ((i %2) ==0))
                  And I don't understand how can someone write one custom constructor and forget to write second.

                  Please tell me that you are just few week old student of Java, or you are heavilly overworked person.

                  Comment


                  • #10
                    Originally posted by raghar


                    And I don't understand how can someone write one custom constructor and forget to write second.

                    Please tell me that you are just few week old student of Java, or you are heavilly overworked person.
                    got my first 'idiots guide' book the end of Febuary, weve all got to start sometime!!

                    i'll get there in the end, in the meantime, be on standby.....!!

                    Comment


                    • #11
                      Well, it took me 6 months to find difference between public main (String ) and public main (string). I looked at Delphi at that time period and didn't have time to look at it properly. BTW it was windoze fault. It closed console window so quickly so I have no chance to see error message.

                      Comment


                      • #12
                        I open a dos window for compiling, just so I can see the errors (if they ever occur)
                        I'm building a wagon! On some other part of the internets, obviously (but not that other site).

                        Comment


                        • #13
                          i'm getting a lot of 'Doh!' moments, if you know what i mean?

                          Comment

                          Working...
                          X