View Full Version : [FTC]: Android Studio NullPointerException on TeleOp Init
Recently the build team has finished setting up all of the electronics on our robot so now it's time to test code, aaaaaaand NullPointerException. From what I've gathered, there are many, many different problems which could give this error. Other programs (autonomous and a sensor test) run fine, but whenever I press "Init" on the phone, the app throws the error. I've tried commenting out just about everything I think could be causing the problem, but it still appears. It's likely something wrong in our hardware file because the robot doesn't do much else on initialization, but I can't tell for sure. Thanks in advance to anyone who looks at this code.
Teleop: http://pastebin.com/YpYwXARb
RobotHardware: http://pastebin.com/bVq1kHKr
Christopher149
23-11-2016, 12:00
Looking at what you posted, you have big chunk of code between start() and loop() that isn't actually in a function (it should all be in loop()). As such, I am curious how your code is compiling as of now. But if you get it into loop(), it should be mostly fine.
A second, smaller issue, is that you never assign a value to buttonPushDelta, but I think Java defaults it to zero.
Line 49 is weird without a function declaration.
JohnMMcD
30-11-2016, 12:47
From what I've gathered, there are many, many different problems which could give this error.
In my experience, the NullPointerException is almost always caused by invoking an object's methods before initializing the object via the hardware map. The object might be a motor, servo, sensor, etc. -- anything that gets initialized via hardwareMap.get().
I think that's your problem here, too. The code that's not in a method (lines 49-131) is running as soon at the op mode is instantiated, which is BEFORE the opmode's "init" method is invoked. Since the "init" method initializes the robot via the hardware map, any command such as "robot.driveRight.setPower(right);" will throw a NPE.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.