简体   繁体   English

java.lang.System.arraycopy的java.lang.ArrayStoreException(Native方法)

[英]java.lang.ArrayStoreException at java.lang.System.arraycopy(Native Method)

        int toSize=toMailIds.size();
        InternetAddress[] address=new InternetAddress[toSize];
        address=toMailIds.toArray(address);

Here toMailIds is arraylist. 这里toMailIds是arraylist。

Iam getting the following exception. 我得到以下异常。

java.lang.ArrayStoreException java.lang.ArrayStoreException

You are going to have to use a loop in this case: 在这种情况下,您将不得不使用循环:

int toSize=toMailIds.size();
InternetAddress[] address=new InternetAddress[toSize];

for (int i = 0; i < toSize; i++) {
    address[i] = new InternetAddress(toMailIds.get(i));
}

If a list stores Strings, the toArray method will not create InternetAddress objects from them automatically. 如果列表存储字符串,则toArray方法不会自动从它们创建InternetAddress对象。

address=toMailIds.toArray() ; address=toMailIds.toArray() ; is enough here. 这就够了 But type of address array should be Object[] 但是address数组的类型应该是Object[]

Example

List<String> list=new ArrayList<>();
Object[] atr=list.toArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hai.main(Hai.java:20)处java.util.ArrayList.toArray的java.lang.System.arraycopy(本机方法)处的java.lang.ArrayStoreException(Hai.java:20) - java.lang.ArrayStoreException at java.lang.System.arraycopy(Native Method) at java.util.ArrayList.toArray(Unknown Source) at Hai.main(Hai.java:20) java.lang.System.arraycopy(本机方法)冻结CPU内核 - java.lang.System.arraycopy (Native Method) freezes CPU cores 线程“主”中的异常java.lang.System.arraycopy上的java.lang.ArrayIndexOutOfBoundsException(本机方法) - Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) java.lang.ArrayStoreException - java.lang.ArrayStoreException 异常:java.lang.ArrayStoreException - Exception: java.lang.ArrayStoreException java.lang.System.arraycopy() 是否使用浅拷贝? - Does java.lang.System.arraycopy() use a shallow copy? 具有不同实现方式的字典; java.lang.ArrayStoreException - dictionary with different implementations; java.lang.ArrayStoreException java.lang.ArrayStoreException IBM Websphere - java.lang.ArrayStoreException IBM Websphere 列表到数组上的 java.lang.ArrayStoreException - java.lang.ArrayStoreException on List to Array java.lang.NoSuchMethodError:将XmlPullParser与Robolectric一起使用的java.lang.System.arraycopy - java.lang.NoSuchMethodError: java.lang.System.arraycopy using XmlPullParser with Robolectric
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM