Log in

View Full Version : Initialization Error


Peragore
12-01-2013, 10:34
Hey guys,

Working on our code this year, we have been encountering an error on the initialization of the code. Tracing it back, we get the error (java.lang.IllegalStateException: Network Tables has already been initialized).

I cannot figure out why this error happens, as it happens when we create a new SimpleRobotTemplate project. Any help would be appreciated.


[cRIO] java.lang.IllegalStateException: Network tables has already been initialized
[cRIO] at edu.wpi.first.wpilibj.networktables.NetworkTable.c heckInit(NetworkTable.java:45)
[cRIO] at edu.wpi.first.wpilibj.networktables.NetworkTable.s etServerMode(NetworkTable.java:59)
[cRIO] at edu.wpi.first.wpilibj.RobotBase.<init>(RobotBase.java:57)
[cRIO] at edu.wpi.first.wpilibj.SimpleRobot.<init>(SimpleRobot.java:31)
[cRIO] at edu.wpi.first.wpilibj.templates.Team3373.<init>(Team3373.java:82)
[cRIO] at edu.wpi.first.wpilibj.templates.Shooter.<init>(Shooter.java:14)
[cRIO] at edu.wpi.first.wpilibj.templates.Team3373.<init>(Team3373.java:37)
[cRIO] in virtual method #11 of com.sun.squawk.Klass(bci=53)
[cRIO] at com.sun.squawk.imp.MIDletMainWrapper.main(99)
[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)


Thanks for any help,

Philip Mulford, Team 3373

mitchellweb1
12-01-2013, 15:12
Does you code have any static fields/blocks in your code? It seems that your code does something which triggers the lazy initialization of network tables before the RobotBase constructor runs.

Peragore
12-01-2013, 15:26
There are no static fields/blocks in the code. If it would help, the link to our GitHub is https://github.com/Peragore/Team3373_2013.git

My best guess was an incomplete include.

mitchellweb1
12-01-2013, 15:37
Oh ok. So your problem is that your code creates multiple instances of the Team3373 class which extends SimpleRobot. This causes the SimpleRobot/RobotBase constructor to be called multiple times which causes some initialization code to run twice. Even if the SimpleRobot constructor didn't fail you would still have errors because you would be creating multiple Tallon objects on the same port (Team3373:32-33). I would suggest that instead you look to take the code in line 30-81 and break it out into a helper base class and declare the your motors and sensors static so that they don't get created multiple times. You probably also want to make all of the fields with sensor values methods because currently they will only get values once when the code loads and will not change after that.

Peragore
12-01-2013, 20:29
Thanks for the write-up! We took a second look at the code, and pretty much found the same thing, with Shooter extending the main file, and then having the main file referencing shooter methods, thereby breaking it. So we went (I believe it is on the GitHub at this point), and used the "this" pointer to make it so we can access the variables of the main class in the Shooter class. So, we fixed it! Thank you for your input!