博客来源:
需要调用系统System.arraycopy,的方法,在调用的过程中出现错误
我的程序如下:
public static void main(String[] args) {
Byte[] bytes = new Byte[102];
byte[] byte_name = "xiaoming".getBytes();
System.arraycopy(byte_name, 0, bytes, 5, byte_name.length);
for (byte bb :bytes) {
System.out.print(bb);
}
}
报错如下: ArrayStoreException? 数组存储异常?
"C:\Program Files\Java\jdk1.8.0_271\bin\java.exe" ...
Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at online.wemnemg.component.Test.main(Test.java:9)
Process finished with exit code 1
对的,就是数组存储异常,经过排查发现!! 我两个数组中使用的不是一个类型,(Byte,byte)更改为一致后,错误消失