質問

I get NullPointerException while trying to write to a file:

        RobocodeFileWriter fileWriter=new RobocodeFileWriter("test.txt");
        for (int i = 0; i < state.countstates; i++)
            for (int j = 0; j < state.countactions; j++)
                fileWriter.write((int) table[i][j]);
        }

The exception:

java.lang.NullPointerException
    at net.sf.robocode.host.security.ThreadManager.createRobotFileStream(ThreadManager.java:136)
    at robocode.RobocodeFileOutputStream.<init>(RobocodeFileOutputStream.java:88)
    at robocode.RobocodeFileOutputStream.<init>(RobocodeFileOutputStream.java:69)
    at robocode.RobocodeFileWriter.<init>(RobocodeFileWriter.java:69)
    at QTable.saveData(QTable.java:79)
    at MyFirstRobot.saveToFile(MyFirstRobot.java:471)
    at MyFirstRobot.onDeath(MyFirstRobot.java:414)
    at robocode.DeathEvent.dispatch(DeathEvent.java:63)
    at robocode.Event$HiddenEventHelper.dispatch(Event.java:259)
    at net.sf.robocode.security.HiddenAccess.dispatch(HiddenAccess.java:191)
    at net.sf.robocode.host.events.EventManager.dispatch(EventManager.java:422)
    at net.sf.robocode.host.events.EventManager.processEvents(EventManager.java:376)
    at net.sf.robocode.host.proxies.BasicRobotProxy.executeImpl(BasicRobotProxy.java:412)
    at net.sf.robocode.host.proxies.BasicRobotProxy.execute(BasicRobotProxy.java:121)
    at robocode.AdvancedRobot.execute(AdvancedRobot.java:549)
    at MyFirstRobot.run(MyFirstRobot.java:68)
    at net.sf.robocode.host.proxies.HostingRobotProxy.callUserCode(HostingRobotProxy.java:274)
    at net.sf.robocode.host.proxies.HostingRobotProxy.run(HostingRobotProxy.java:221)
    at java.lang.Thread.run(Thread.java:695)

This exception occurs even if I disable the security manager by passing -DNOSECURITY=true My robocode version is 1.8.3.0 and doing the development on Mac. Any help is appreciated.

役に立ちましたか?

解決

I had the same problem, I added the package at the beginning and it worked. Did you add the package at the beginning? You can create a package to put all your codes in that package and then you need to include the package in each class in your code as well and it should work just fine.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top