[英]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.