Java SE和JDK为最新更新时,Windows 10 JNI错误

时间:2018-11-07 17:10:13

标签: java windows cmd runtime-error

我的cmd给我以下答复

Error: A JNI error has occurred, please check your installation and try 
again
Exception in thread "main" java.lang.UnsupportedClassVersionError: 
musicplayer has been compiled by a more recent version of the Java Runtime 
(class file version 55.0), this version of the Java Runtime only recognizes 
class file versions up to 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) 

我多次重新安装了Java SE和JDK。我还在线搜索了一个小时或找到了一个解决方案,但找不到遮阳篷。我在最新版本上获得了Java SE和JDK。 Java versions

这是我的代码,无论代码是否执行了应做的工作,我都希望它能够运行

        import javax.sound.midi.InvalidMidiDataException;
    import javax.sound.midi.MidiEvent;
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.MidiUnavailableException;
    import javax.sound.midi.Sequence;
    import javax.sound.midi.Sequencer;
    import javax.sound.midi.ShortMessage;
    import javax.sound.midi.Track;


    public class MusicPlayer {

    public static int frequencyToMidi(double frequency) {
    //TODO return midi note. hint: round the result and cast it to an integer

    double p;
    p=69+12*(Math.log(frequency/440)/Math.log(2));
    Math.round(p);
    int pp = (int)(p);

    return 0;
}

    public static MidiEvent makeEvent(int command, int channel, int firstByte, int secondByte, int tick) throws InvalidMidiDataException {
    //TODO return midi event. hint: use short message

    ShortMessage msg = new ShortMessage();
    msg.setMessage(command, channel, firstByte, secondByte);
    MidiEvent event = new MidiEvent(msg, tick);

    return null;
}

public static void addNote(Track track, int channel, int midiNoteNumber, int velocity, int tickOn, int tickOff) throws InvalidMidiDataException {
    //TODO add note on/off. hint: use ShortMessage.NOTE_ON and ShortMessage.NOTE_OFF

    MidiEvent event1 = makeEvent(ShortMessage.NOTE_ON, 1, midiNoteNumber, velocity, tickOn);
    track.add(event1);
    MidiEvent event2 = makeEvent(ShortMessage.NOTE_OFF, 1, midiNoteNumber, velocity, tickOff);
    track.add(event2);
}

public static void fillTrack(Track track) throws InvalidMidiDataException {

        MidiEvent event3 = makeEvent(ShortMessage.CONTROL_CHANGE, 1, 127, 1, 0);
        track.add(event3);
        MidiEvent event4 = makeEvent(ShortMessage.PROGRAM_CHANGE, 1, 1, 0, 0);
        track.add(event4);


    addNote(track, 1, frequencyToMidi(659.26), 100, 1, 3);
    addNote(track, 1, frequencyToMidi(622.25), 100, 5, 7);
    addNote(track, 1, frequencyToMidi(493.88), 100, 9, 11);
    addNote(track, 1, frequencyToMidi(587.33), 100, 13, 15);
    addNote(track, 1, frequencyToMidi(523.25), 100, 17, 19);
    addNote(track, 1, frequencyToMidi(440), 100, 21, 25);

    //TODO change control. hint: use ShortMessage.CONTROL_CHANGE
    //TODO change program. hint: use ShortMessage.PROGRAM_CHANGE

    //TODO add note using your implementation of addNote
}

public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException {
    //initializes a sequencer and creates a track on it with a tempo of 220 bpm
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();

    Sequence seq = new Sequence(Sequence.PPQ, 4);
    Track track = seq.createTrack();

    fillTrack(track);

    sequencer.setSequence(seq);
    sequencer.setTempoInBPM(220);

    //plays the track
    sequencer.start();
}

}

0 个答案:

没有答案