0

I'm trying to make a java application which uses Java Sound API. I found a source code and when I tried to run it I got this exception. There was another question like mine in stackoverflow but the answer wasn't helpful for me.

The StackTrace of this exception is as below:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: No line matching interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian is supported.

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)

The part of source code that generates this error is:

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

It is in Recorder class.

Some more information that may be helpful: I'm using win7-64bit, and my sound card is on board.

S Kh
  • 105
  • 2
  • 9
  • Obviously you passed an incorrect value `at prj.Recorder.(Recorder.java:54)`. Unless you post some source code this will get closed as "not a real question". – Jim Garrison Nov 25 '12 at 21:21
  • Is this part of code enough ? – S Kh Nov 25 '12 at 21:30
  • FWIW - it worked for me. It's probably not a coding error but an audio hardware configuration thing. I am running on an iMac using the built-in audio. You should probably include details about platform, audio card etc. – Guido Simone Nov 25 '12 at 21:59
  • You mean that maybe I should reconfigure my audio card ? – S Kh Nov 25 '12 at 22:03
  • I honestly don't know. I'm just guessing. But at the very least add everything you can about your platform and audio hardware in the hope that some audio guru reads the question and can help you. – Guido Simone Nov 25 '12 at 22:18
  • I think your guess is right. Because I can run this application using another computer but now I can't do that. Of course I don't know exactly which information may be useful about my platform and audio hardware to add here. – S Kh Nov 25 '12 at 22:24
  • Start with the basics: Windows, Mac or Linux. What brand hardware - apple, dell? What OS version? Are you using the built-in audio or some fancy sound card. – Guido Simone Nov 25 '12 at 22:40
  • Perhaps you are not alone ... http://stackoverflow.com/questions/1727511/java-sound-api-to-access-the-system-master-volume-control-in-vista-and-win-7 – Guido Simone Nov 25 '12 at 22:54
  • @Guido Simone:Thanks for your link.I told before that I'm using win7. But the other computer that I run this program on it, had win7, too and I didn't use IAudioEndpointVolume API. – S Kh Nov 25 '12 at 23:04

0 Answers0