如何消除错误?
我正在编写文本编辑器,它实际上应该说出当前按下的键。我设法做到了,我什至准备了文件。一切都工作正常,但是当符号数量超过 29 时,编译器会说:
javax.sound.sampled.LineUnavailableException: unable to obtain a line
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.connect(PulseAudioDataLine.java:279)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:102)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:289)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
at TextEditor$AreaListener.keyPressed(Main.java:81)
at java.awt.Component.processKeyEvent(Component.java:6161)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2801)
at java.awt.Component.processEvent(Component.java:5980)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4564)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4390)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1881)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:749)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1025)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:892)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:713)
at java.awt.Component.dispatchEventImpl(Component.java:4434)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4390)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
这是我的源代码的一部分,其中描述了一个实现 KeyListener 接口的类。这个类是我的主文本区域的监听器。
class AreaListener implements KeyListener {
@Override public void keyPressed( KeyEvent e) {
try {
AudioInputStream result1 = AudioSystem.getAudioInputStream(new File("/home/nikkka/Desktop/alphabet/blank.wav"));;
if(new Character(e.getKeyChar()).isLetter(e.getKeyChar()))
result1 = AudioSystem.getAudioInputStream(new File("/home/nikkka/Desktop/alphabet/"+e.getKeyChar()+"_EDITOR.wav"));
DataLine.Info info = new DataLine.Info(Clip.class, result1.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(result1);
clip.start();
} catch(Exception e1) {e1.printStackTrace();}}
@Override public void keyReleased(KeyEvent e) {}
@Override public void keyTyped( KeyEvent e) {
}
}
我看不出问题是什么?...此外,为什么适用于前 29 个符号的东西不应该适用于更多符号?也许是因为我必须在 clip.start()
之后通过 clip.close()
关闭剪辑?请帮忙:-S
I'm writing text editor that is supposed to actually SAY the current key that is pressed. I managed to do that, I even prepared files. And everything works just fine, but when the amount of symbols becomes more than 29, the compiler says:
javax.sound.sampled.LineUnavailableException: unable to obtain a line
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.connect(PulseAudioDataLine.java:279)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:102)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:289)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
at TextEditor$AreaListener.keyPressed(Main.java:81)
at java.awt.Component.processKeyEvent(Component.java:6161)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2801)
at java.awt.Component.processEvent(Component.java:5980)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4564)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4390)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1881)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:749)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1025)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:892)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:713)
at java.awt.Component.dispatchEventImpl(Component.java:4434)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4390)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:649)
at java.awt.EventQueue.access$000(EventQueue.java:96)
at java.awt.EventQueue$1.run(EventQueue.java:608)
at java.awt.EventQueue$1.run(EventQueue.java:606)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$2.run(EventQueue.java:622)
at java.awt.EventQueue$2.run(EventQueue.java:620)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:619)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
Here is the part of my source code where is described a class that implements KeyListener interface. This class is a listener of my main text area.
class AreaListener implements KeyListener {
@Override public void keyPressed( KeyEvent e) {
try {
AudioInputStream result1 = AudioSystem.getAudioInputStream(new File("/home/nikkka/Desktop/alphabet/blank.wav"));;
if(new Character(e.getKeyChar()).isLetter(e.getKeyChar()))
result1 = AudioSystem.getAudioInputStream(new File("/home/nikkka/Desktop/alphabet/"+e.getKeyChar()+"_EDITOR.wav"));
DataLine.Info info = new DataLine.Info(Clip.class, result1.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(result1);
clip.start();
} catch(Exception e1) {e1.printStackTrace();}}
@Override public void keyReleased(KeyEvent e) {}
@Override public void keyTyped( KeyEvent e) {
}
}
I can't see what's the problem?... Moreover, why something that works for first 29 symbols, shouldn't work on more? Maybe it's because I have to close the clip by clip.close()
after clip.start()
? Please, help :-S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到此错误是因为
根据描述的文档,由于资源限制,线路
不可用这里。我认为你应该关闭
Line
与Line.close()
方法。编辑:
正确的方法如下:
Clip
对象,或者创建用于处理输入区域的对象,Clip
对象在输入区域中的stop()
和close()
当应用程序退出或销毁输入区域时Clip
这将节省资源。
You get this error because the
Line
is not available due to resource restrictions, according to the documentations described here.I think you should close the
Line
after you used it with theLine.close()
method.EDIT:
The proper way of doing it could be the following:
Clip
object when starting the application or creating objects for handling the input areaClip
object when the key is pressed in the input areastop()
andclose()
theClip
when the application is exiting or destroying the input areaThis would save the resources.
这不是编译器错误消息。
这是一个运行时错误,我认为这意味着它无法读取声音文件中的数据。文件已损坏或格式不受支持。
This is not a compiler error message.
It is a runtime error which I would assume means it could not read the data in the sound file. Either the file is corrupt or has a format which is not supported.