Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java could not open/create prefs error

Tags:

java

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();
    }
}
like image 313
Harry Kitchener Avatar asked May 18 '14 09:05

Harry Kitchener


1 Answers

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.

like image 195
Osanda Deshan Avatar answered Oct 01 '22 03:10

Osanda Deshan