我有同样的问题,我必须在Android中使用AudioInputStream,所以我使用了inputStream。我的代码是:
public int read (float b[],int off, int len) throws IOException
{
int b_len = len * 2;
if(buffer == null || buffer.length < b_len){
buffer = new byte[b_len];
System.out.println(buffer);
}
int ret = inputStream.read(buffer, 0, b_len);
if(ret == -1)
{
return -1;
} else
{
converter.toFloatArray(buffer, b, off, ret / 2);
return ret / 2;
}
}
其中b =缓冲区,off = 0且len = buffer.length;但是有这些错误:
06-29 02:00:01.421: E/AndroidRuntime(7183): FATAL EXCEPTION: main
06-29 02:00:01.421: E/AndroidRuntime(7183): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.read/com.example.read.MainActivity}: java.lang.NullPointerException
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.os.Looper.loop(Looper.java:123)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread.main(ActivityThread.java:4633)
06-29 02:00:01.421: E/AndroidRuntime(7183): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 02:00:01.421: E/AndroidRuntime(7183): at java.lang.reflect.Method.invoke(Method.java:521)
06-29 02:00:01.421: E/AndroidRuntime(7183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-29 02:00:01.421: E/AndroidRuntime(7183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-29 02:00:01.421: E/AndroidRuntime(7183): at dalvik.system.NativeStart.main(Native Method)
06-29 02:00:01.421: E/AndroidRuntime(7183): Caused by: java.lang.NullPointerException
06-29 02:00:01.421: E/AndroidRuntime(7183): at com.example.read.AudioFloatInputStream.read(AudioFloatInputStream.java:53)
06-29 02:00:01.421: E/AndroidRuntime(7183): at com.example.read.MainActivity.onCreate(MainActivity.java:194)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-29 02:00:01.421: E/AndroidRuntime(7183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
06-29 02:00:01.421: E/AndroidRuntime(7183): ... 11 more
为什么呢?你能救我吗?
由于