Announcement

Collapse
No announcement yet.

Error with thread.sleep

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

  • Error with thread.sleep

    So I am trying to make an autonomous mode, and when I try to make a wait like this ( thread.sleep(2000); ) There is an error message about an Interrupted Exception. There is an option to fix it with a try, catch loop, but that gets fairly annoying every time. Is there any way to have a diffrent wait, or a way to easily fix this? Any questions or suggestions welcomed. Just ask any clarifying questions if any needed.

  • #2
    Sure is!

    Code:
    //Simply change this:
    public void runOpMode() {
    
    //To this:
    public void runOpMode() throws InterruptedException {
    Happy programming!

    Comment


    • #3
      wow... How could I seriously not think of that. LOL Thanks so much.

      Comment


      • #4
        Originally posted by 4634 Programmer View Post
        Sure is!

        Code:
        //Simply change this:
        public void runOpMode() {
        
        //To this:
        public void runOpMode() throws InterruptedException {
        Happy programming!
        Actually, with the latest SDK, "throws InterruptedException" has been removed from the runOpMode() method to permit cleanup code to be run after the driver presses stop.

        Instead of just adding it back in again, simply use

        sleep(2000)

        instead of

        thread.sleep(2000)

        This custom version of sleep is part of the linearOpMode class, and takes care of the exception handling.

        Comment


        • #5
          Thanks again. I shall try it!

          Comment


          • #6
            Is there any way I can keep it in an normal opmode?

            Comment


            • #7
              Never mind. I was able to use a "wait(5000);" instead of a "thread.sleep" but thanks for all your advice.

              Comment


              • #8
                Or not. Sorry, I guess it didn't work. Still wondering about if I can do it in regular opmode

                Comment


                • #9
                  Originally posted by patfanman101 View Post
                  Is there any way I can keep it in an normal opmode?
                  As posted earlier...

                  Get rid of just "throws InterruptedException" and use sleep() instead of thread.sleep().

                  Comment


                  • #10
                    I tried. It doesn't work, it still says "Interrupted Exception." What I mean by regular op mode is

                    public class Autonomous extends OpMode
                    Instead of public class Autonomous extends LinearOpMode

                    Comment

                    Working...
                    X