Search code examples
javabeagleboneblackbeagleboard

libbulldog null pointer exception on createBoard()


I am working on a class project that involves controlling pins on the beagle bone black, it is running the stock debian os.

I added the library and was able to have the following code work.

Code:

package swerve.tracker.robot;

import org.bulldog.beagleboneblack.BBBNames;
import org.bulldog.beagleboneblack.gpio.BBBPwm;
import org.bulldog.core.gpio.Pin;
import org.bulldog.core.gpio.Pwm;
import org.bulldog.core.platform.Board;
import org.bulldog.core.platform.Platform;
import org.bulldog.core.util.BulldogUtil;
import org.bulldog.devices.servo.Servo;

/**
 * Created by yoseph on 5/10/2016.
 */
public class Robot {
    private Board board;
    public void init() {
        //board = Platform.createBoard();
        //Pwm pwm = board.getPin(BBBNames.ECAPPWM0_P9_42).as(Pwm.class);
        //Servo servo = new Servo(pwm);
        //servo.setAngle(180.0f);
        System.out.println("Started");
        BulldogUtil.sleepMs(1000);
        System.out.println("Waited 1 second.");
        //servo.setAngle(90.0f);
        //BulldogUtil.sleepMs(1000);
        System.out.println("Waited another second.");
        //servo.setAngle(0.0f);
        //BulldogUtil.sleepMs(1000);
        System.out.println("Finished initializing.");
    }

    public void update() {

    }

    public void finish() {
    }

    public Board getBoard() {
        return board;
    }
}

Console Out:

yoseph1998@beaglebone:~/.../$ java -jar SwerveTracker.jar
Started
Waited 1 second.
Waited another second.
Finished initializing.

Once I uncomment Board board = Platform.createBoard() I get a NullPointerException from the library caused by that line, I've searched online for this problem and found nothing, I followed the examples and guides and found nothing. Here is the error.

Console Out:

yoseph1998@beaglebone:~/.../$ java -jar SwerveTracker.jar
Exception in thread "Thread-0" java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:459)
    at org.bulldog.core.platform.AbstractBoard.setProperty(AbstractBoard.java:94)
    at org.bulldog.beagleboneblack.BeagleBoneBlack.createProperties(BeagleBoneBlack.java:265)
    at org.bulldog.beagleboneblack.BeagleBoneBlack.<init>(BeagleBoneBlack.java:33)
    at org.bulldog.beagleboneblack.BeagleBoneBlackBoardFactory.createBoard(BeagleBoneBlackBoardFactory.java:17)
    at org.bulldog.core.platform.Platform.createBoard(Platform.java:13)
    at swerve.tracker.robot.Robot.init(Robot.java:18)
    at swerve.tracker.robot.framework.Scheduler.run(Scheduler.java:45)
    at java.lang.Thread.run(Thread.java:745)

Could anyone help, if not then does anyone have any recommendatons on a better library than libbulldog?


Solution

  • Since I am running this as a java program it has the guest user permission. Any file that requires root access the program won't be able to read or write to. When the program calls the Platform.createBoard() it tries to access the /etc/dogtag as ekaerovets mentioned.

    There are two ways to fix this:

    • Chnage the permission on the file to be read only. But then other methods and functions that need to access files with permission will also fail.
    • Give the program sudo permission. This is the best option because it means the library will be able to access what it was designed to access.

    Solution

    Run the program with sudo permission as follows

    sudo java -jar SwerveTracker.jar