【发布时间】:2014-04-04 23:35:06
【问题描述】:
我通过蓝牙实时接收 30000 个字符串,大约每秒 1000 个。我将数据解析为双精度数据并尝试将这 30000 个数据点存储到多维 array[30000][1] 中。但是,当我运行 Android 应用程序时,由于 ArrayIndexOutofBoundException,它在几个点后崩溃。
我确实意识到这可以在单个数组中完成,但我最终会增加数组的宽度。
存储的数组大小 = [30000][1]
转换的数组大小=[1]
蓝牙聊天
case MESSAGE_READ:
for (int a = 0; a < 30000; a++) {
byte[] readBuf = (byte[]) msg.obj;
try {
String readMessage = new String(readBuf, 0, msg.arg1);
mConversationArrayAdapter.add("Voltage: " + readMessage);
double[] convert = new double[1];
for (int z = 0; z < 1; z++) {
convert[z] = Double.parseDouble(readMessage);
}
for (int j = 0; j < 1; j++) {
stored[a][j] = convert[a];
}
} catch (NumberFormatException e) {
System.err.println("NumberFormatException: " + e.getMessage());
}
}
finalValue = new HjorthClass(stored);
if (finalValue.returnSum() == true) {
seizureResult.setText("A Seizure has been detected");
}
break;
logcat;
04-04 22:44:17.406: E/AndroidRuntime(14619): FATAL EXCEPTION: main
04-04 22:44:17.406: E/AndroidRuntime(14619): java.lang.ArrayIndexOutOfBoundsException
04-04 22:44:17.406: E/AndroidRuntime(14619): at com.example.android.BluetoothChat.BluetoothChat$2.handleMessage(BluetoothChat.java:311)
04-04 22:44:17.406: E/AndroidRuntime(14619): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 22:44:17.406: E/AndroidRuntime(14619): at android.os.Looper.loop(Looper.java:130)
04-04 22:44:17.406: E/AndroidRuntime(14619): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 22:44:17.406: E/AndroidRuntime(14619): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 22:44:17.406: E/AndroidRuntime(14619): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 22:44:17.406: E/AndroidRuntime(14619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 22:44:17.406: E/AndroidRuntime(14619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 22:44:17.406: E/AndroidRuntime(14619): at dalvik.system.NativeStart.main(Native Method)
【问题讨论】:
-
如果你的第二维是 [1] 你真的需要它吗?
-
我最终会在未来将其更改为 [2]、[3]。我想首先测试它是否适用。我的 hjorthClass 也需要一个二维数组。
-
数组太多,你没有包含所有的大小
-
我将编辑我的问题以包含数组大小
标签: java android arrays bluetooth indexoutofboundsexception