10

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();
    }
}
Tiny
  • 27,221
  • 105
  • 339
  • 599
Harry Kitchener
  • 255
  • 1
  • 2
  • 8

4 Answers4

10

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.

Osanda Deshan
  • 1,473
  • 3
  • 14
  • 30
  • Work for me, thanks. More details, just **right click on "JavaSoft" - "New" -"Key", and rename the key to "Prefs"**. Re-run the gradle task, the warning message is gone. – MadHatter Jun 04 '21 at 06:41
8

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.

david.pfx
  • 10,520
  • 3
  • 30
  • 63
6

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

Sean
  • 45
  • 7
szaroblekitny
  • 130
  • 1
  • 5
2

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);
}
Gegomu
  • 21
  • 3
  • 4
    This is not a solution, it only make the WARNING log disappear and shouldn't be used. – lmo Nov 04 '19 at 14:46