Java 无法打开/创建首选项错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23720446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:51:52  来源:igfitidea点击:

Java could not open/create prefs error

java

提问by Harry Kitchener

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

我正在尝试播放 MIDI 音频,但是每当我这样做时,它都会返回错误`

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 regeditand my permissions are on EVERYONE, but it just doesn't want to work.

我已经进入regedit并且我的权限是 on EVERYONE,但它只是不想工作。

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();
    }
}

回答by szaroblekitny

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

这是一个众所周知的 Windows 问题。试试吧

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

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft.....右键图标,然后将权限改为完全操作

回答by david.pfx

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.

这是一个已知的 Java 错误,在 Windows 10 和更新 112 上仍然存在。只需从提升的命令提示符运行该程序一次,它就会消失。

回答by Gegomu

It's java problem

这是java的问题

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

我尝试只使用 USER_PREFERENCES 来解决,但是 WindowsPreferences 类有这个代码

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.

所以它尝试读取 systemPreferences yes 或 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

我尝试在 HKEY_LOCAL_MACHINE 上更改权限,但现在在 win-10 中它不起作用。过去,在 win-7 中它有效。这不重要,如果您使用 USER_PREFS,它只是一个跟踪

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

这是我的(棘手的)解决方案...在主方法中或在使用 Preferences 之前编写此代码

static {
    PlatformLogger logger = PlatformLogger.getLogger("java.util.prefs");
    logger.setLevel(Level.SEVERE);
}

回答by Osanda Deshan

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

我在 Windows 10 64 位上遇到了这个问题,并且能够通过手动创建以下注册表项来解决该问题。

HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

Hope this helps for the Windows users.

希望这对 Windows 用户有所帮助。