Java could not open/create prefs error

4

I am trying to get MIDI audio to play, but when ever I do this it keeps returning the error `

May 18, 2014 10:23:29 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 
         0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

I have gone into regedit and my permissions are on EVERYONE, but it just doesn't want to work.

CODE

import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;

public class Sound {

    public static void main(String args[]) throws MidiUnavailableException {
        int channel = 0;
        int volume = 80;
        int duration = 200;

        Synthesizer synth;
        synth = MidiSystem.getSynthesizer();
        synth.open();
        MidiChannel[] channels = synth.getChannels();
        channels[channel].noteOn(60, volume); // C note
        synth.close();
    }
}
java
asked on Stack Overflow May 18, 2014 by Harry Kitchener • edited May 18, 2014 by Tiny

4 Answers

5

I was faced this issue on Windows 10 64-bit and was able to resolve the problem by manually creating the following registry key.

HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

Hope this helps for the Windows users.

answered on Stack Overflow Jun 4, 2019 by Osanda Deshan
4

It's a known Java bug, still around on Windows 10 and update 112. Just run the program once from an elevated command prompt and it goes away.

answered on Stack Overflow Jan 3, 2018 by david.pfx
3

It's a very well known Windows problem. Just try it:

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft.....Right click the icon, then change the permission to full operation

answered on Stack Overflow Mar 10, 2017 by szaroblekitny • edited Nov 29, 2019 by Sean
0

It's java problem

I've try to solve using only USER_PREFERENCES, but the WindowsPreferences class has this code

static final Preferences userRoot = new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

static final Preferences systemRoot = new windowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

So it try to read systemPreferences yes or yes.

I've try changing priviledges on HKEY_LOCAL_MACHINE but now in win-10 it doesn't works. In the past, in win-7 it worked. It does not important, it's only a trace if you use USER_PREFS

This is my (tricky) solution... write this code in the main method or before using Preferences

static {
    PlatformLogger logger = PlatformLogger.getLogger("java.util.prefs");
    logger.setLevel(Level.SEVERE);
}
answered on Stack Overflow Mar 15, 2019 by Gegomu • edited Mar 15, 2019 by Gegomu

User contributions licensed under CC BY-SA 3.0