Weird Null error on robot code

We’re getting a weird error called nullpointerexception on the following lines of code
public void arcadeDrive(double movespeed, double rotatespeed) {
differentialDrive.arcadeDrive(xbox.getLeftY(), xbox.getLeftX());
}
I have an Xbox controller set up but im still trying to find the right port for it. im thinking that its the double movespeed and rotatespeed that is messing this up. Ill link my SRC file. if you need any other code pls ask.

Thanks

EDIT: I just figured it out, thanks y’all!

1 Like

Are you linking the right code? I cannot find that function that is giving the error.

Also it’s helpful to say which file the codes in. Another small note from looking at your code is you can make a XboxController object instead of using Joystick.

You can confirm the correct input by using Driver Station and looking at the USB inputs tab pictured below. If you aren’t sure that the port is correct in the code that would be a good starting point for debugging as you can’t initialize and object with something that doesn’t exist. It’ll likely result in a NULL reference error like mentioned.
image

I’m not on my normal computer so I don’t have any inputs attached right now.

While on lines 55-57 of Robot.java you declare your joysticks, on line 70 you only seem to initialize your “xbox” joystick, meaning your other two variables are still null. Initializing those here will fix your null pointer.

However, what it seems like you actually want to do is have the xbox be a XboxController and not a Joystick, and then call the xbox getLeftY and getRightY methods

1 Like