0

我正在尝试制作一个使用 Java Sound API 的 Java 应用程序。我找到了一个源代码,当我尝试运行它时,我得到了这个异常。在 stackoverflow 中还有一个类似我的问题,但答案对我没有帮助。

该异常的 StackTrace 如下:

线程“AWT-EventQueue-0”java.lang.IllegalArgumentException 中的异常:没有行匹配接口 TargetDataLine 支持格式 PCM_SIGNED 44100.0 Hz,16 位,立体声,4 字节/帧,支持大端。

at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:476)
at prj.Recorder.<init>(Recorder.java:54)
at prj.CForm.startRecording(ChatForm.java:202)
at prj.CForm.TalkjbtnActionPerformed(ChatForm.java:482)
at prj.CForm.access$600(ChatForm.java:28)
at prj.CForm$4.actionPerformed(ChatForm.java:315)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6463)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6228)
at java.awt.Container.processEvent(Container.java:2213)
at java.awt.Component.dispatchEventImpl(Component.java:4819)
at java.awt.Container.dispatchEventImpl(Container.java:2271)
at java.awt.Component.dispatchEvent(Component.java:4645)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4816)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4476)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4406)
at java.awt.Container.dispatchEventImpl(Container.java:2257)
at java.awt.Window.dispatchEventImpl(Window.java:2677)
at java.awt.Component.dispatchEvent(Component.java:4645)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

产生此错误的源代码部分是:

audioFormat = new AudioFormat(44100f, 16, 2, true, true);
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
    TargetDataLine targetDataLine = null;

    try {
        // This Line Makes this exception
        targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
        targetDataLine.open(audioFormat);
    }
    catch (LineUnavailableException e) {
        System.err.println("Error: Unable to get a recording line");
        gotrecordingline = false;
    }

它在 Recorder 类中。

一些可能有帮助的更多信息:我使用的是win7-64bit,并且我的声卡在板上。

4

0 回答 0