Go to Post Just wanted to know some of your favorite physics and math equasions during build seasions thanks. mine is pathagriom therom - team 3311 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 10-02-2014, 21:18
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 588
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: NetworkTables Null Pointer Exception

There's a second overloaded getNumber() method that takes two parameters, the name and a default value. If it can't find the named value, then the default value is supplied instead of the error being thrown. Take a look at this example:

http://wpilib.screenstepslive.com/s/...client-pc-side
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2014, 14:18
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
Re: NetworkTables Null Pointer Exception

Thanks for the suggestion, but that didn't work. We are still getting a null pointer.
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2014, 14:23
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,561
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: NetworkTables Null Pointer Exception

Quote:
Originally Posted by sarangmittal View Post
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.
if you posted a screenshot of the TableViewer, we might be able to help better.
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2014, 14:36
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
Re: NetworkTables Null Pointer Exception

So we realized how dumb we were being after some frustration. Our mentor pointed out that we weren't constructing the vision class in our main class. That got rid of one error (Thank god for mentors). Also, in the code above we are creating 2 networktables, a subtle but fatal error.

Thanks for everyone who tried to help.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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