Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   NullPointerException at drivecode (http://www.chiefdelphi.com/forums/showthread.php?t=113313)

r0306 12-02-2013 05:21

NullPointerException at drivecode
 
When we run our drive code, it throws the following error:
Code:

[cRIO] java.lang.NullPointerException
[cRIO]    at edu.wpi.first.wpilibj.RobotDrive.arcadeDrive(RobotDrive.java:342)
[cRIO]    at edu.wpi.first.wpilibj.RobotDrive.arcadeDrive(RobotDrive.java:354)
[cRIO]    at Robot2013.RobotMain.teleopPeriodic(RobotMain.java:90)
[cRIO]    at edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:165)
[cRIO]    at edu.wpi.first.wpilibj.RobotBase.startApp(RobotBase.java:169)
[cRIO]    in virtual method #10 of javax.microedition.midlet.MIDlet(bci=17)
[cRIO]    at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(64)
[cRIO]    at com.sun.squawk.imp.MIDletMainWrapper.main(110)
[cRIO]    in virtual method #95 of com.sun.squawk.Klass(bci=25)
[cRIO]    at com.sun.squawk.Isolate.run(1506)
[cRIO]    at java.lang.Thread.run(231)
[cRIO]    in virtual method #47 of com.sun.squawk.VMThread(bci=42)
[cRIO]    in static method #3 of com.sun.squawk.VM(bci=6)

Code:

public class RobotMain extends IterativeRobot
{

    public static RobotDrive driveTrain;
    public static Joystick leftStick;
   
    public void robotInit()
    {

        driveTrain = new RobotDrive(4, 3, 1, 2);

        driveTrain.setSafetyEnabled(false);

    }


    public void autonomousPeriodic()
    {
       
    }

    public void teleopPeriodic()
    {

        driveTrain.arcadeDrive(leftStick); //line 90

    }

    public void testPeriodic() {

    }
}

The motors aren't running at all and I don't get what could've gone wrong here as the code seems fine.

MagiChau 12-02-2013 05:44

Re: NullPointerException at drivecode
 
You never instantiated the joystick so there is no Joystick to get any values from.

Code:

Joystick leftStick = new Joystick(1);


All times are GMT -5. The time now is 10:10.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi