空指针异常而写的SourceDataLine [英] Null pointer exception while writing to SourceDataLine

查看:147
本文介绍了空指针异常而写的SourceDataLine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有音频采样的字节数组。我要玩的话,所以我尽量把它写进SourceDataLine的:

I have a byte array with audio samples. I want to play it, so I try to write it into SourceDataLine:

SourceDataLine sample;
private byte[] samplebytes;

...

sample.start();
sample.write(samplebytes, 0, samplebytes.length);
sample.drain();
sample.stop();
sample.close();
sample = null;

和我得到这样的:

java.lang.NullPointerException
at virtualcut.Sample.<init>(Sample.java:45)
at virtualcut.model.SelectionModel.setPosition(SelectionModel.scala:79)
at draggable.DraggableComponent$2.mouseReleased(DraggableComponent.java:128)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
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)

我是新在Java中,有时我真不明白是什么cousing NullPointerException异常 - 这是这样的一个时期:(

I'm new In Java and sometimes I don't get what is cousing NullPointerException - this is one of those times :(.

推荐答案

您还没有实例化样品。你需要调用新的SourceDataLine()

You haven't instantiated sample. You need to call new SourceDataLine().

这篇关于空指针异常而写的SourceDataLine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆