Preferences in Java - error 5

1

I am trying to store some preferences in java but I get a compile error which points to a registry permission problem (at least when run on windows). The compile error is:

WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

A lot of other solutions point to registry editing but this is not acceptable solution for users, and nor is it for users to run as Admin.

Here is the code snippet:

        // Create Place to store prefs
    Preferences prefs = Preferences.userNodeForPackage(GetFiles.class);
    final String PREF_DATABASE = "Directory Location of Database";
    final String PREF_DIRECTORY = "Directory to Scan for Pol1310";
    prefs.put(PREF_DIRECTORY, "C:\\Users\\Al\\My Documents");

    String defaultValue = "test";
    System.out.println("This is the dir " +prefs.get(PREF_DIRECTORY, defaultValue));

The error happens on this line:

final String PREF_DATABASE = "Directory Location of Database";

I am actually wondering if because its a "final" string, and it is already set then its creating the error, because the output of the printlin correctly shows C:\Users\Al\My Documents - NOT the default value "test".

Cheers

-Al

java
preferences
asked on Stack Overflow Mar 6, 2016 by Al Grant

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0