Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
Like Tree2Likes

Thread: Help:P i don't even have a title

  1. #21
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    right now i am not getting error but i am 100% sure that my code is wrong.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Help:P i don't even have a title

    Is that a question or are you just talking?

  3. #23
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    i am just mumbling....

    Java Code:
    package sample_sara;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.io.IOException;
    import javax.swing.JFrame;
    import reve.sara.agent.BaseAgent.Status;
    import reve.sara.agent.BaseMotileAgent;
    import reve.sara.agent.MotileAgentEvent;
    import reve.sara.agent.MotileAgentListener;
    import reve.sara.helpers.NavMesh2D;
    import reve.sara.helpers.NavMesh2DView;
    
    
    public class CastleKeeper extends BaseMotileAgent implements MotileAgentListener {  
    
        class StringThread implements Runnable 
        {
            
                    
            StringThread(String name) {
    
            super(name);
    
            if (status.equals(Status.INITIALIZED)) {
    
                System.out.println("[" + getName() + "] Initialized.");
                System.out.print("[" + getName() + "] Creating spatial representation window... ");
                System.out.print("[" + getName() + "] Connecting... ");
                try {
                    connect("127.0.0.1", 4444);
                }
                catch (IOException ex) {
                    System.out.println("\n[" + getName() + "] Network error while connecting (" + ex.getMessage() + ")");
                }
    
                if (status.equals(Status.CONNECTED)) {
                    System.out.println("Done.");
                    System.out.print("[" + getName() + "] Attaching motor effector to motor accesspoint... ");
                    act("attach motor motorAccessPoint");
                    System.out.println("Done.");
    
                    System.out.print("[" + getName() + "] Selecting translation action... ");
                    act("select motor move translate");
                    System.out.println("Done.");
    
                    System.out.print("[" + getName() + "] Selecting rotation action... ");
                    act("select motor turn rotate");
                    System.out.println("Done.");
    
                    sense();
                    update();
                }
            }
           // frame.repaint();
        }
    
            public void run () {
                    for (int i = 0; i != 600; i++) {
                    setSpeed(3);
                    moveTo(0,11);
                    moveTo(-6,11);
                    moveTo(-6,0);
                    moveTo(-6,-8);
                    moveTo(12,-8);
                    moveTo(12,0);
                    }
            }
            
    }
        
      
        public static void main (String args [] ) 
        {      
            StringThread thread = new StringThread("blabla");
            new Thread(thread).start();
        }
    
        @Override
        public void translationCompleted(MotileAgentEvent ev) {
            System.out.println("[" + getName() + "] Translation completed.");
            sense();
            update();
            //frame.repaint();
        }
    
    
        @Override
        public void rotationCompleted(MotileAgentEvent ev) {
            System.out.println("[" + getName() + "] Rotation completed.");
            sense();
            update();
            //frame.repaint();
        }
    
        @Override
        public void segmentStarted(MotileAgentEvent ev) {
        }
    
    
        @Override
        public void segmentCompleted(MotileAgentEvent ev) {
        }
    
    
        @Override
        public void pathCompleted(MotileAgentEvent ev) {
            System.out.println("[" + getName() + "] Bye bye!");
            hangup();
        }
    
    
    }

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context
    at sample_sara.CastleKeeper.main(CastleKeeper.java:74 )

    can you please help me?
    some people next door are having a party for hours..... :S

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Help:P i don't even have a title

    non-static variable this cannot be referenced from a static context
    The line number doesn't map to your posted code. It could be refering to the inner class???

    The error message means that you are trying to use a class variable that only exists when an instance of the class exists from a static method.
    You need to have an instance of the class to be able to access non-static class variables.

  5. #25
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    it is the first line in my main.... yes ok and how do i get this instance? :/

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Help:P i don't even have a title

    What happens if you make the class static so the main() method can use it?
    static class StringThread ...

  7. #27
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    i get 2 more errors:P
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.lang.Object.<init>
    at sample_sara.CastleKeeper$StringThread.<init>(Castl eKeeper.java:21)
    at sample_sara.CastleKeeper.main(CastleKeeper.java:73 )

    the one is for my first line in main and the other for the super(main)....
    and also all my code in StringThread becomes red:P i am so messed with these classes i dont understand how i can make it work...

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Help:P i don't even have a title

    You continue making the program more complicated.
    Why have the inner class do what used to be done in the constructor?

  9. #29
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    what do you mean?? i dont understand...

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Help:P i don't even have a title

    You created an inner class and moved code into it that used to be in the class's constructor.
    Why? Does that make the program more complicated?

    A class can implement more than one interface:

    CastleKeeper extends BaseMotileAgent implements MotileAgentListener, Runnable

  11. #31
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    i moved it because i dont know how to initialize the object... now i put it back put i still cannot make it work..

  12. #32
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    wow that last hint was a good one! thanks! the object initialized, no errors!
    OMG thank you so much... i did not know that it could implement another class... that was the problem prom the beginning i think..
    i hope that when i make the second thread i wont have any problems.... i will come back and post here again tomorrow... maybe tonight... i'll see. it's 12:41 am here.
    thaaaaaaaaaaaaaaaaaaanks :)

  13. #33
    Ophelia is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Help:P i don't even have a title

    Ohhhhhhhhhhhhh you are amazing.. i could not wait and i tried this now! it does work! it created to objects!

    Greetings from Greece.
    <3

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 19
    Last Post: 06-10-2011, 08:58 PM
  2. Title not displayer
    By weezy2894 in forum Java Applets
    Replies: 13
    Last Post: 04-18-2011, 05:12 AM
  3. Change the title
    By AndrewSD in forum NetBeans
    Replies: 1
    Last Post: 01-11-2011, 04:23 AM
  4. set * at tab title
    By keffie91 in forum Advanced Java
    Replies: 7
    Last Post: 10-06-2008, 08:21 PM

Posting Permissions

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