When I am trying to access data files I am getting Nulls as a result of getDataFile(...) and getDataDirectory().
My robot is being developed in external IDE, and it's classpath is added correctly (code without data access is running properly).
Anonymous
The question is how can I make data writing working?
Have a look at the source file for the SittingDuck sample robot. It gives a simple example of how to read and write to a file.
Also make sure you have added your class path in Robocode to where your robots a located.
Options -> Preferences -> Development Options
Thank you for such quick response.
I did try code from SittingDuck example, and it ended with the same error. Also I have already defined class path properly as I was able to run my robots properly without using File access.
Here is example stack trace from my error (Learner is my robot name):
Line 76 in Learner.java corresponds to the 43rd line from SittingDuck.java which is opening file for reading.
Similar error happens few lines later when robot tries to open file for printing.
Thanks for the stack trace. I have checked the code.
The NullPointerException is thrown as Robocode cannot create and/or write to a data file for the robots.
I need more details. Do you have write permissions to write to the files (especially the 'robot' directory) under the 'robocode' directory where Robocode is installed?
Are you able to run SittingDuck without this error directly from Robocode? If not, something is wrong with your installation of Robocode or you have not got write permissions to the files. If it does work, your class path under the Development Options is not correct. Try to point to the 'robot' directory (containing all robots) - not directly on a individual robot directory.
I am on windows running as admin, so it couldn't be lack of access. I run SittingDuck from within the robocode, so I started messing with my code. As it turned out it I forgot to put Lerner into package. After doing so problems disappeared, so I think my class path is ok after all.
I guess robocode doesn't like default package robots, which isn't that bad as it forces good practices. However I think it would be good to show some warning 'bout that after loading such robot.
Anyway thank you for assistance and good trails which led me to final conclusion.
You are welcome.
I agree with you regarding getting no warnings for robots that have been created for the default package. Hence I created a bug report for it here:
https://sourceforge.net/p/robocode/bugs/358/