non static variable cannot be referenced from a static context

前端 未结 5 988
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 05:31

I am a Java newbie, so please bear with me and help.

I aim to first play then record sound.

I use netbeans IDE 6.8. Here is the code:

import java         


        
5条回答
  •  臣服心动
    2021-01-29 06:05

    Replace your main with :

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Reg1 r = new Reg1();
                try {
                    AudioInputStream audio = AudioSystem.getAudioInputStream(new File("name.wav"));
                    Clip clip = AudioSystem.getClip();
                    clip.open(audio);
                    clip.start();
                }
                catch (Exception e) {
                    System.out.println(e);
                }
                r.captureAudio();
            }
        });
    }
    

提交回复
热议问题