0

What causes the following warning/error message? And how to get rid of it?

Dec 31, 2021 3:10:05 PM 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 a class NotePlayer.java and a test program NotePlayerTest.java, and when I run the latter, it runs ok, but I get the above warning message, which I would like to rectify.

A snippet of NotePlayer:

import javax.sound.midi.*;

public class NotePlayer {
   
   /**
     *  Program: NotePlayer.java
     *  Purpose: Simple musical note player, plays a single note.
     *  Creator: Chris Clarke
     *  Created: July 2007
     */
   
   MidiChannel[]    mc;
   Synthesizer      synth;
   Instrument[]     instr;
   int          tmpo = 500; // fixed tempo of 120 beats/minute
   boolean      done = false;
   
   public void loadInstr() {
      // only necessary to run this method once
      if (done) return;
      
      for (int voice=0; voice<16; voice++) {
         try {
            synth = MidiSystem.getSynthesizer();
            synth.open();
            mc = new MidiChannel[16];
            mc = synth.getChannels();
            instr = synth.getDefaultSoundbank() .getInstruments();
            synth.loadInstrument (instr[voice]); // 0-15
         }
         catch (Exception e) { System.out.println("Caught exception"); }
      }
      done = true;
   } // end loadInstr()
   
   public void playNote(int voice, int pitch, int duration, int vol) {
      // play note
      mc[voice].noteOn(pitch, vol);
      for (int i=0; i<duration; i++) {
         try {
            Thread.sleep(tmpo/4); // pause for one semiquaver
         } catch (InterruptedException e) {}
      }
      // stop playing note
      mc[voice].noteOff(pitch, vol);
   } // end playNote(int, int, int, int)

And my NotePlayerTest.java is as follows:

public class NotePlayerTest {
   
   /**
     *  Program:    NotePlayerTest.java by Chris Clarke
     *  Created:    04 July 2007
     *  Purpose:    Test my NotePlayer class
     */
   
   public static void main(String[] args) {
      NotePlayer np = new NotePlayer();
      np.loadInstr();
      // parameters are voice (0-15), pitch, duration, volume
      np.playNote(2, 42, 4, 600);
      np.playNote(2, 46, 4, 600);
      np.playNote(2, 49, 4, 600);
   }
}
Kaan
  • 5,434
  • 3
  • 19
  • 41
  • 1
    Does this answer your question? [Suppressing Java Preferences Systemroot Warning](https://stackoverflow.com/questions/39120693/suppressing-java-preferences-systemroot-warning) – Thomas Kläger Dec 31 '21 at 16:42
  • @ThomasKläger That question only asks how to suppress the logging. – Mark Rotteveel Jan 01 '22 at 10:35
  • Alternatively this could answer your question: https://stackoverflow.com/questions/23720446/java-could-not-open-create-prefs-error – Thomas Kläger Jan 01 '22 at 14:36
  • Note that this was a know bug in Java and has been fixed since Java 8u192 and Java 9b123 (see [Java Bug Tracker](https://stackoverflow.com/questions/23720446)). If you are using an older version of Java you should upgrade your Java version. – Thomas Kläger Jan 01 '22 at 15:20

0 Answers0