java.lang.StringIndexOutOfBoundsException:length = 11; regionStart = 0; regionLength = 2560

时间:2015-07-18 12:44:18

标签: java

我无法摆脱这个错误。我有很多但与我的代码无关(问题)

 if (recorder.getState() == AudioRecord.STATE_INITIALIZED){
                    Log.d("VS", "Recorder working....c");
                    recorder.startRecording();}

                BufferedWriter input;
                while(status == true) {


                    minBufSize = recorder.read(buffer, 0, buffer.length);
                    (buffer,buffer.length,destination,port);





                    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
                    out.write(buffer.toString(), 0, buffer.length);



                    out.flush();
提前thnaks ......!

1 个答案:

答案 0 :(得分:2)

此异常的原因非常明显,字符串长度仅为11,缓冲区长度为2560。

out.write(buffer.toString(), 0, buffer.toString().length());

应该工作,它使用字符串长度而不是缓冲区长度。 但如果这是你想要的,你可以使用

out.write(buffer.toString());