Announcement

Collapse
No announcement yet.

Error: attempt to invoke inter face method

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error: attempt to invoke inter face method

    Ive been getting this error when I run my program :Error: User code threw an uncaught exception: NullPointerException - Attempt to invoke interface method voidcom.qualcomm.robotcore.hardware.DcMotor.setmod e()

  • #2
    This is the code


    import com.qualcomm.robotcore.eventloop.opmode.Autonomous ; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de; import com.qualcomm.robotcore.hardware.DcMotor; /** * Created by phs-robotics on 12/18/2017. */ @Autonomous (name = "EncoderAuto") public class EncodersTest extends LinearOpMode { DcMotor frontLeft = null; DcMotor backLeft = null; DcMotor frontRight = null; DcMotor backRight = null; public void runOpMode() throws InterruptedException { frontLeft = hardwareMap.dcMotor.get("frontLeftDrive"); backLeft = hardwareMap.dcMotor.get("backLeftDrive"); frontRight = hardwareMap.dcMotor.get("frontRightDrive"); frontLeft = hardwareMap.dcMotor.get("frontLeftDrive"); telemetry.addData("Status", "Initialized"); telemetry.update(); frontLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); //Resets encoders backLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); frontRight.setMode(DcMotor.RunMode.RESET_ENCODERS) ; backRight.setMode(DcMotor.RunMode.RESET_ENCODERS); while(frontLeft.getCurrentPosition() != 0 || backLeft.getCurrentPosition() != 0 ||frontRight.getCurrentPosition() != 0 || backRight.getCurrentPosition() != 0) { //Ensures encoders are zero frontLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); backLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); frontRight.setMode(DcMotor.RunMode.RESET_ENCODERS) ; backRight.setMode(DcMotor.RunMode.RESET_ENCODERS); waitOneFullHardwareCycle(); //Needed within all loops } frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODE R); //Sets mode to use encoders backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER ); frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCOD ER); backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODE R); waitForStart(); frontLeft.setTargetPosition(1120); //Sets motor to move 1120 ticks backLeft.setTargetPosition(1120); frontRight.setTargetPosition(1120); backRight.setTargetPosition(1120); frontLeft.setPower(.5); backLeft.setPower(.5); frontRight.setPower(.5); backRight.setPower(.5); while(frontLeft.getCurrentPosition() < frontLeft.getTargetPosition() || backLeft.getCurrentPosition() < backLeft.getTargetPosition() || frontRight.getCurrentPosition() < frontRight.getTargetPosition() || backRight.getCurrentPosition() < backRight.getTargetPosition()) { //While target has not been reached waitOneFullHardwareCycle(); //Needed within all loops } frontLeft.setPower(0); backLeft.setPower(0); frontRight.setPower(0); backRight.setPower(0); } }

    Comment


    • #3

      import com.qualcomm.robotcore.eventloop.opmode.Autonomous ; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de; import com.qualcomm.robotcore.hardware.DcMotor; /** * Created by phs-robotics on 12/18/2017. */ @Autonomous (name = "EncoderAuto") public class EncodersTest extends LinearOpMode { DcMotor frontLeft = null; DcMotor backLeft = null; DcMotor frontRight = null; DcMotor backRight = null; public void runOpMode() throws NullPointerException { frontLeft = hardwareMap.dcMotor.get("frontLeftDrive"); backLeft = hardwareMap.dcMotor.get("backLeftDrive"); frontRight = hardwareMap.dcMotor.get("frontRightDrive"); frontLeft = hardwareMap.dcMotor.get("frontLeftDrive"); telemetry.addData("Status", "Initialized"); telemetry.update(); frontLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); //Resets encoders backLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); frontRight.setMode(DcMotor.RunMode.RESET_ENCODERS) ; backRight.setMode(DcMotor.RunMode.RESET_ENCODERS); while (frontLeft.getCurrentPosition() != 0 || backLeft.getCurrentPosition() != 0 || frontRight.getCurrentPosition() != 0 || backRight.getCurrentPosition() != 0) { //Ensures encoders are zero frontLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); backLeft.setMode(DcMotor.RunMode.RESET_ENCODERS); frontRight.setMode(DcMotor.RunMode.RESET_ENCODERS) ; backRight.setMode(DcMotor.RunMode.RESET_ENCODERS); } frontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODE R); //Sets mode to use encoders backLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER ); frontRight.setMode(DcMotor.RunMode.RUN_USING_ENCOD ER); backRight.setMode(DcMotor.RunMode.RUN_USING_ENCODE R); waitForStart(); frontLeft.setTargetPosition(1120); //Sets motor to move 1120 ticks backLeft.setTargetPosition(1120); frontRight.setTargetPosition(1120); backRight.setTargetPosition(1120); frontLeft.setPower(.5); backLeft.setPower(.5); frontRight.setPower(.5); backRight.setPower(.5); while (frontLeft.getCurrentPosition() < frontLeft.getTargetPosition() || backLeft.getCurrentPosition() < backLeft.getTargetPosition() || frontRight.getCurrentPosition() < frontRight.getTargetPosition() || backRight.getCurrentPosition() < backRight.getTargetPosition()) { //While target has not been reached frontLeft.setPower(0); backLeft.setPower(0); frontRight.setPower(0); backRight.setPower(0); } } }

      Comment

      Working...
      X