View Single Post
  #1   Spotlight this post!  
Unread 10-02-2014, 18:50
sarangmittal's Avatar
sarangmittal sarangmittal is offline
Registered User
FRC #1683 (Techno Titans)
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Atlanta GA
Posts: 20
sarangmittal is an unknown quantity at this point
NetworkTables Null Pointer Exception

Hey guys,

We are trying to use RoboRealm to do our vision tracking, and we are able to write the values from RoboRealm onto the NetworkTables (we can see the value changing in TableViewer). However, when we try to run code that gets the value from the NetworkTable and use it in the code, we get a Nullpointer.

Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException;

public class Vision {
    NetworkTable table;
    double COG_X;

public Vision(){
        NetworkTable table = NetworkTable.getTable("TitanTable");
    }
public double test(){
        try {
            COG_X = table.getNumber("COG_X");
            return COG_X;
        } catch (TableKeyNotDefinedException exp){
            System.out.println("Exception caught");
            return 0;
        }

    }
}
The null pointer pops up from the table.getNumber("COG_X") function. We are thinking its an issue of the code not finding anything named COG_X, but we don't know what to put instead.

Also, when I tried to look in the API for Network Tables, (in the 2013.0.589 update), it was missing. One other member of the team hadn't updated from 2013.0.427 yet, and the API had documentation for NetworkTables. Anyone know what's going on there?

Thanks for the help!

Last edited by sarangmittal : 10-02-2014 at 18:58. Reason: Grammar
Reply With Quote