Struggling with a Java JDBC:sqlite connection using Intellij [duplicate] - java

This question already has answers here:
How to connect SQLite with Java?
(9 answers)
Closed 3 years ago.
My full project is on Github.com/DSkilton
I have tried dozens of ways to get this to work, I've read about classpaths, using Class.forName() and not using it, Xerials JDBC instructions which suggests using / rather than escaping \ for the path String. I've read through some of Oracles suggestions, Stackoverflow and SQlites tutorial on how to set up. I've really tried to research this but am still coming up blank!
Inside my src folder are the following folders: controller, images, lib, model, sample and view.
In the controller folder is databaseConnect.java and in the lib folder is jdbc-api-1.4.jar.
In my databaseConnect file I have the following:
public static void Connection() {
final String connectionUrl = "jdbc:sqlite:D:\\Users\\IdeaProject\\modus\\src\\model\\modus.db";
try {
Connection con = DriverManager.getConnection(connectionUrl);
System.out.println("Connected");
//while(returnStatement.next()) {
//System.out.println("rs.getString");
//}
} catch (SQLException e) {
e.printStackTrace();
}
The error I get is:
java.sql.SQLException: No suitable driver found for jdbc:sqlite:D:\\Users\\Duncan Skilton\\IdeaProject\\modus\\src\\model\\modus.db
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at controller.databaseConnect.Connection(databaseConnect.java:16)
at sample.Main.main(Main.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Process finished with exit code -1
Anything you can suggest will be massively appreciated!

You're missing Driver for your dbms. Add this to your pom.xml when using maven:
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.25.2</version>
</dependency>
or this
implementation 'org.xerial:sqlite-jdbc:3.25.2'
to your build.gradle when using gradle.
P.S.:I don't think url is correct either. You don't pass the url to file on your drive, find some examples of urls for sqlite on the internet.

Related

Pentaho Data Integration - General Error in Dialog

When I try to edit my database connections, I get the "General Error in Dialog" message. Upon clicking details, I get the following:
java.lang.NullPointerException at
org.pentaho.di.ui.core.database.dialog.XulDatabaseDialog.open(XulDatabaseDialog.java:113)
at
org.pentaho.di.ui.core.database.dialog.DatabaseDialog.open(DatabaseDialog.java:61)
at
org.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.editConnection(SpoonDBDelegate.java:96)
at org.pentaho.di.ui.spoon.Spoon.editConnection(Spoon.java:2725) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:313)
at
org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:157)
at
org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:141)
at
org.pentaho.ui.xul.jface.tags.JfaceMenuitem.access$100(JfaceMenuitem.java:43)
at
org.pentaho.ui.xul.jface.tags.JfaceMenuitem$1.run(JfaceMenuitem.java:106)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4385) at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1512) at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1535) at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520) at
org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1324) at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3789)
at org.pentaho.di.ui.spoon.Spoon.readAndDispatch(Spoon.java:1385) at
org.pentaho.di.ui.spoon.Spoon.waitForDispose(Spoon.java:7968) at
org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:9350) at
org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:711) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.pentaho.commons.launcher.Launcher.main(Launcher.java:92)
I'm using Java version 8 update 261. I know that PDI requires Java 8 so I don't understand why I'm having this issue. Currently, I have to delete and then create a new database connection for each job, which is really tedious.
How do I resolve this issue? Or is there another way to set my database connections so that I don't have to create a new one for each job?
I don't know about your error message, but to share connections IN YOUR PC you have the option in the View tab:
I have an empty transformation, so all the DB connections shown are the shared ones, if I had a new connection in the transformation it would be also shown but the connection name wouldn't be in bold letters.
Beware, the shared connections information are only available in your PC, and the connection information is copied to the transformation or job, so if you change the information in your shared connection, you need to reopen all the transformations and jobs that use it and save them with the new information.
In the .kettle folder in your user folder there's a shared.xml file with the shared connections information.

JSON Path 2.3.0 conflicts with hadoop 2.7 Environment JSON-smart1.2.0.jar

Have a Input of JSON inside HDFS location
It is required to parse the JSON and to aggregate results
To do am using the PIG UDF which are using JSON-path libraries
On the hadoop2.7 environment jar: json-smart1.2, json-path1.2 are hardbinded
Whenever I execute the PIG Mapreduce which throws me below Exception
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
In-order to solve the problem tried below options
Option 1:
Tried setting Registering the json-smart2.3.jar & json-path2.3.0.jar
But no promising results (As the Jar it was referencing is json-path1.2.jar)
Option 2:
Downgrading my module dependencies to json-path1.2.jar
No results
Option 3:
Using Custom classLoaders tried to load the jar of JSON-path2.3.0 jar it
loaded the class went into issues of Org.slf4j binding
There were multiple binding paths identified, But went problems with sun.misc classloader
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NullPointerException
at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Caused by: java.lang.ExceptionInInitializerError
at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
... 6 more
Caused by: java.lang.IllegalStateException: Unexpected initialization failure
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:167)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
... 8 more
Caused by: java.lang.NullPointerException
at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
... 13 more
Can some one suggest me to solve this problem, Can find one stackoverflow link where it was telling about weblogic and not a generalized solution which can be applied on Hadoop2.7 also (JSON Parser -java.lang.NoSuchFieldError: defaultReader)
As hadoop environment(Pig, hdfs, Hive & etc) is using json-path-2.3.0, Its better user Mapper logic should use another version "jsonpath-1.0.jar" will solve the problem
Provide the custom implementation to load/parse the JSON so that we can avoid using Json-smart-2.x/1.x of Hadoop/lib
public static void changeJsonPathConfig() {
if (!configChanged) {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new GsonJsonProvider(
new GsonBuilder().serializeNulls().create());
private final MappingProvider mappingProvider = new GsonMappingProvider();
#Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
#Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
#Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
configChanged = true;
}
}

Javafx NullPointerException when Playing Sounds [duplicate]

This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 2 years ago.
I am working on a Javafx game and have been attempting to implement some sound using the following code:
URL laserResource = getClass().getResource("LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toString());
This code is instantiated in the main class before any methods. I have a module called JavaFxImages which contains all my resources including my sounds and I have been successfully able to access images for ImageView from the folder through code such as Image asteroid = new Image("Asteroid.png");.
However, when I run my game I get a NullPointerException at the line for my audio clip. I have spent the past many hours researching and trying every different way to access this resource. I've tried many permutations of the URL ("JavaFxImages/LaserBlast.wav", Desktop/JavaFxImages/LaserBlast.wav", etc.), but every time it has the same error. I'm really at a loss for what is wrong with the code. I would greatly appreciate any help that can be given.
Thanks in advance!
The full error message is given below.
Error Message:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class sample.Main
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:819)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
at sample.Main.<init>(Main.java:76)
... 10 more
Your error mostly happens on Itellij IDEA - Javafx Project
Instead of:
URL laserResource = getClass().getResource("LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toString());
Use:
//By default your Package_NAME is: sample
File laserResource = new File("src/Package_NAME/LaserBlast.wav");
AudioClip laserPlayer = new AudioClip(laserResource.toURI().toString());

Eclipse IDE doesn't recognize mysql driver

This has been extremely frustrating, especially since I've been all over the forums and have followed all the directions, as far as I can tell.
I am trying to create a connection to a local mysql database. First I downloaded the mysql driver from http://dev.mysql.com/downloads/connector/j using the platform independent TAR (I'm on ubuntu). Then I placed the resultant JAR into a new folder I created for my project call /lib, and then right-clicked and selected "Add to Build Path". It now shows up as a Referenced Library.
For the code, I am doing the typical things you would do:
try {
Class.forName("com.mysql.jdbc.Driver");
String db_url = "jdbc:mysql://localhost/project";
connect = DriverManager.getConnection(db_url, "user", "password");
statement = connect.createStatement();
resultSet = statement.executeQuery("select * from database.table");
while (resultSet.next()) {
int id = resultSet.getInt("ID");
String name = resultSet.getString("Name");
System.out.println("(ID: " + id + ") (Name: " + name + ")");
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
But for whatever reason, I still get "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver cannot be found"
I'm sure it's something completely idiotic on my part, but any pointers as to what I'm missing?
Here is the stack trace:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver cannot be found by com.personal.recipes_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.personal.recipes.test.TestUtils.execute(TestUtils.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:850)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:743)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:727)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:662)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1392)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3742)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3363)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:162)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
So I probably didn't explain my problem well enough before. The question specifically related to getting my Eclipse RCP application to see the driver. After talking to a friend he reminded me that I needed to add the mysql jar to the .MF file directly. Once I knew that I found a ton of posts on various forums answering my question.
I added the following line and I'm able to make the connection to the database without issue:
"Bundle-ClassPath: lib/mysql-connector-java-5.1.30-bin.jar, ."
The (.) at the end also was very important and stymied me for a few minutes.
I just made a quick copy / paste of your code into a fresh project, installed the driver in lib... works like a charm. So did you do something before the code snippet?

Java file input and output

I have the below method which is meant to append information to a file but I get the error below. In the method I use parts of robocode API which inherits from java.io.InputStream
All the permissions on the files and folders seem fine and the file does exist
static public void logInfo(String info)
{
RobocodeFileWriter in;
try {
in = new RobocodeFileWriter("log.txt");
in.append(info);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SYSTEM: An error occurred during initialization of itc.solomon
SYSTEM: java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory.
java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory.
at robocode.security.RobocodeSecurityManager.handleSecurityProblem(Unknown Source)
at robocode.security.RobocodeSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.File.exists(File.java:748)
at robocode.RobocodeFileOutputStream.(Unknown Source)
at robocode.RobocodeFileOutputStream.(Unknown Source)
at robocode.RobocodeFileWriter.(Unknown Source)
at itc.CFile.logInfo(CFile.java:16)
at itc.solomon.(solomon.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at robocode.peer.proxies.HostingRobotProxy.loadRobotRound(Unknown Source)
at robocode.peer.proxies.HostingRobotProxy.run(Unknown Source)
at java.lang.Thread.run(Thread.java:636)
See this sample:
http://code.google.com/p/robocode/source/browse/robocode/trunk/robocode.samples/src/main/java/sample/SittingDuck.java
I think getDataFile("log.txt") will give you proper location.
I've searched a bit about this problem. It seems that there's a bug in the robocode package, awkwardly solved by:
while (!dataIsLoaded) {
try {
tryToReadData;
dataIsLoaded = true;
} catch (AnyException e) {}
}
It's a quite awful way to solve the problems, for many reasons (ignoring exceptions, busy-waiting, etc.) A more sane way would be downgrading the robocode package to a previous, more stable version.
See search results here.

Categories

Resources