Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Unhandled exception instantiating robot (http://www.chiefdelphi.com/forums/showthread.php?t=132926)

Yonatan Rubin 15-01-2015 11:03

Unhandled exception instantiating robot
 
when I try to run the code on roboRio the driver station write:

ERROR Unhandled exception instantiating robot org.usfirst.frc.team2212.robot.Robot java.lang.ExceptionInInitializerError at [java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:259), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:197)]

can anybody help me understand what does it mean and how could I solve it?

notmattlythgoe 15-01-2015 11:05

Re: Unhandled exception instantiating robot
 
Quote:

Originally Posted by Yonatan Rubin (Post 1428662)
when I try to get code on robot the driver station write:

ERROR Unhandled exception instantiating robot org.usfirst.frc.team2212.robot.Robot java.lang.ExceptionInInitializerError at [java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:259), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:197)]

can anybody help me understand what does it mean and how could I solve it?

Can you post the code from your Robot class?

Ozuru 15-01-2015 11:18

Re: Unhandled exception instantiating robot
 
Read the error code. It's telling you to look at a line in your Robot.java - pastebin your robot.java.

dash121 15-01-2015 19:43

Re: Unhandled exception instantiating robot
 
Quote:

Originally Posted by Ozuru (Post 1428675)
Read the error code. It's telling you to look at a line in your Robot.java - pastebin your robot.java.

I am having the same problem. The specific error that is given "ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.PWM.startLiveWindowMode(PWM. java:484), org.usfirst.frc.team4085.robot.Robot.teleopPeriodi c(Robot.java:117), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:150), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]"

Can you help me?

Code:

package org.usfirst.frc.team4085.robot;

import java.io.IOException;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
import edu.wpi.first.wpilibj.PowerDistributionPanel;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.Talon;


import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;

import edu.wpi.first.wpilibj.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {

        public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
        public static OI oi;

    Command autonomousCommand;
    Joystick lstick = new Joystick(0);
    Joystick rstick = new Joystick(1);
    PowerDistributionPanel PDP = new PowerDistributionPanel();
    BuiltInAccelerometer Accel = new BuiltInAccelerometer();
    LiveWindow Window = new LiveWindow();
    Talon Left = new Talon(0);
    Talon Right = new Talon(1);
    RobotDrive chassis = new RobotDrive(Left,Right);
    SmartDashboard smart = new SmartDashboard();

    /**
    * This function is run when the robot is first started up and should bDahe
    * used for any initialization code.
    */
    public void robotInit() {
                oi = new OI();
        // instantiate the command used for the autonomous period
        autonomousCommand = new ExampleCommand();
    }
       
        public void disabledPeriodic() {
                Scheduler.getInstance().run();
        }

    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

    /**
    * This function is called periodically during autonomous
    */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

   
        public void teleopInit() {
                // This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to
        // continue until interrupted by another command, remove
        // this line or comment it out.
        if (autonomousCommand != null) autonomousCommand.cancel();
    }

    /**
    * This function is called when the disabled button is hit.
    * You can use it to reset subsystems before shutting down.
    */
    public void disabledInit(){

    }

    /**
    * This function is called periodically during operator control
    */
    @SuppressWarnings({"static-access" })
        public void teleopPeriodic() {
        Scheduler.getInstance().run();
        double counter = 0.0;
        while(isEnabled())
        {
                smart.putNumber("Timer", counter++);
        }
        while(true)
        {
               
                chassis.setSafetyEnabled(false);
               
                chassis.tankDrive(lstick, rstick);
               
               
                smart.putNumber("The X Axis", Accel.getX());
               
               
                smart.putNumber("The Y Axis", Accel.getY());
                smart.putNumber("The Z Axis", Accel.getZ());
                smart.putNumber("The Temp of the roboRIO", PDP.getTemperature());
                smart.putNumber("This is the test", smart.getNumber("Put a number here", 1));
               
               
                Window.setEnabled(isEnabled());
                Left.startLiveWindowMode();
                Right.startLiveWindowMode();
                Accel.startLiveWindowMode();
                PDP.startLiveWindowMode();
               
               
                smart.putNumber("Total Current", PDP.getTotalCurrent());
                smart.putNumber("Total Energy", PDP.getTotalEnergy());
                smart.putNumber(" Total Power", PDP.getTotalPower());
                smart.putNumber("Match Time", Timer.getMatchTime());

               
                int inChar = 0;
            System.out.println("Enter a Character:");
            try {
                inChar = System.in.read();
                System.out.print("You entered ");
                System.out.println(inChar);
            }
            catch (IOException e){
                System.out.println("Error reading from user");
            }
           
            int outChar = 5;
                                if (inChar == outChar ){
                                        System.out.println("Hello World");
                                }
                                else
                                {
                                        System.out.println("Not J");
                                }
        }
                        }
               
   
   
    /**
    * This function is called periodically during test mode
    */
    public void testPeriodic() {
        LiveWindow.run();
    }
}


Team3266Spencer 15-01-2015 22:00

Re: Unhandled exception instantiating robot
 
Quote:

Originally Posted by dash121 (Post 1428957)
I am having the same problem. The specific error that is given "ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.PWM.startLiveWindowMode(PWM. java:484), org.usfirst.frc.team4085.robot.Robot.teleopPeriodi c(Robot.java:117), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:150), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]"

Can you help me?

Code:

package org.usfirst.frc.team4085.robot;

import java.io.IOException;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
import edu.wpi.first.wpilibj.PowerDistributionPanel;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.Talon;


import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;

import edu.wpi.first.wpilibj.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {

        public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
        public static OI oi;

    Command autonomousCommand;
    Joystick lstick = new Joystick(0);
    Joystick rstick = new Joystick(1);
    PowerDistributionPanel PDP = new PowerDistributionPanel();
    BuiltInAccelerometer Accel = new BuiltInAccelerometer();
    LiveWindow Window = new LiveWindow();
    Talon Left = new Talon(0);
    Talon Right = new Talon(1);
    RobotDrive chassis = new RobotDrive(Left,Right);
    SmartDashboard smart = new SmartDashboard();

    /**
    * This function is run when the robot is first started up and should bDahe
    * used for any initialization code.
    */
    public void robotInit() {
                oi = new OI();
        // instantiate the command used for the autonomous period
        autonomousCommand = new ExampleCommand();
    }
       
        public void disabledPeriodic() {
                Scheduler.getInstance().run();
        }

    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

    /**
    * This function is called periodically during autonomous
    */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

   
        public void teleopInit() {
                // This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to
        // continue until interrupted by another command, remove
        // this line or comment it out.
        if (autonomousCommand != null) autonomousCommand.cancel();
    }

    /**
    * This function is called when the disabled button is hit.
    * You can use it to reset subsystems before shutting down.
    */
    public void disabledInit(){

    }

    /**
    * This function is called periodically during operator control
    */
    @SuppressWarnings({"static-access" })
        public void teleopPeriodic() {
        Scheduler.getInstance().run();
        double counter = 0.0;
        while(isEnabled())
        {
                smart.putNumber("Timer", counter++);
        }
        while(true)
        {
               
                chassis.setSafetyEnabled(false);
               
                chassis.tankDrive(lstick, rstick);
               
               
                smart.putNumber("The X Axis", Accel.getX());
               
               
                smart.putNumber("The Y Axis", Accel.getY());
                smart.putNumber("The Z Axis", Accel.getZ());
                smart.putNumber("The Temp of the roboRIO", PDP.getTemperature());
                smart.putNumber("This is the test", smart.getNumber("Put a number here", 1));
               
               
                Window.setEnabled(isEnabled());
                Left.startLiveWindowMode();
                Right.startLiveWindowMode();
                Accel.startLiveWindowMode();
                PDP.startLiveWindowMode();
               
               
                smart.putNumber("Total Current", PDP.getTotalCurrent());
                smart.putNumber("Total Energy", PDP.getTotalEnergy());
                smart.putNumber(" Total Power", PDP.getTotalPower());
                smart.putNumber("Match Time", Timer.getMatchTime());

               
                int inChar = 0;
            System.out.println("Enter a Character:");
            try {
                inChar = System.in.read();
                System.out.print("You entered ");
                System.out.println(inChar);
            }
            catch (IOException e){
                System.out.println("Error reading from user");
            }
           
            int outChar = 5;
                                if (inChar == outChar ){
                                        System.out.println("Hello World");
                                }
                                else
                                {
                                        System.out.println("Not J");
                                }
        }
                        }
               
   
   
    /**
    * This function is called periodically during test mode
    */
    public void testPeriodic() {
        LiveWindow.run();
    }
}


I'm not sure about the exception that was thrown but there should not be while(isEnabled()) and while(true) loops inside of your teleopPeriodic method! This function is called periodically and so it is already part of a loop. Therefore you should write the code knowing its going to be called every ~30 ms. Also, you should not be trying to read user input on the rRIO.

RufflesRidge 16-01-2015 07:54

Re: Unhandled exception instantiating robot
 
Quote:

Originally Posted by dash121 (Post 1428957)
I am having the same problem. The specific error that is given "ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.PWM.startLiveWindowMode(PWM. java:484), org.usfirst.frc.team4085.robot.Robot.teleopPeriodi c(Robot.java:117), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:150), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]"

I'm having difficulty figuring out what exactly you are trying to do with this code. It is using the Command based template, but then you have manually altered the TeleopPeriodic method to do a number of strange things. Why are you trying to get user console input on the roboRIO? What are you trying to accomplish with the LiveWindow code? Why are you suppressing the warming that would have told you your code was broken before you ran it?

fsilberberg 16-01-2015 09:53

Re: Unhandled exception instantiating robot
 
Quote:

Originally Posted by dash121 (Post 1428957)
I am having the same problem. The specific error that is given "ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.PWM.startLiveWindowMode(PWM. java:484), org.usfirst.frc.team4085.robot.Robot.teleopPeriodi c(Robot.java:117), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:150), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]"

Can you help me?

Code:

                Window.setEnabled(isEnabled());
                Left.startLiveWindowMode();
                Right.startLiveWindowMode();
                Accel.startLiveWindowMode();
                PDP.startLiveWindowMode();


This is not how you put objects to the LiveWindow. See the examples on using LiveWindow here: http://wpilib.screenstepslive.com/s/...ode-livewindow.


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

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