|
Re: FTC NullPointerException
Thanks again for all the replies. I believe I have added a constructor as Mike explained and passed the hardwareMap to RobotDrive and I still receive the same results: it goes to the catch block. If there is a better place for me ask the question than here I am would be be willing to move it but i appreciate your kindness.
Updated code:
*********************************************
package com.qualcomm.ftcrobotcontroller.opmodes;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
public class Brain extends OpMode {
private int statusDriveInteger = 76;
private RobotDrive rd = new RobotDrive(hardwareMap);
public void init (){
statusDriveInteger = rd.statusRobotDrive();
telemetry.addData("here ",statusDriveInteger);
}
public void loop (){
telemetry.addData("here pre",statusDriveInteger);
rd.setPowerLeftRearDrive(1.0);
telemetry.addData("here post",statusDriveInteger);
}
}
***********************************************
package com.qualcomm.ftcrobotcontroller.opmodes;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;
public class RobotDrive {
int erroroccurred;
DcMotor h_leftRearDrive;
private HardwareMap rd_hardwareMap;
public RobotDrive(HardwareMap hardwareMap)
{
rd_hardwareMap = hardwareMap;
}
public int statusRobotDrive (){
try {
h_leftRearDrive = rd_hardwareMap.dcMotor.get("1");
} catch (Exception p_exception) {
h_leftRearDrive = null;
erroroccurred = 102;
}
return erroroccurred;
}
public void setPowerLeftRearDrive (double p_leftRearDrivePower) {
h_leftRearDrive.setPower(p_leftRearDrivePower);
}
}
|