java .lang.ArrayStoreException - PullRequest
       4

java .lang.ArrayStoreException

0 голосов
/ 23 января 2020

Поскольку я тестирую с помощью Junit, я не могу запустить этот тест. Он говорит только об ошибке и «java .lang.ArrayStoreException» на трассировке сбоя. Было бы здорово помочь, если бы кто-то мог решить мою проблему. LinkedInUser - это объект, который я создал, метод getConnections возвращает тип данных List<LinkedInUser>.

@Test
public void testSort() throws LinkedInException {//Test sorting
    LinkedInUser user0 = new LinkedInUser("Han", null);
    LinkedInUser user1 = new LinkedInUser("LUKE", null);
    LinkedInUser user2 = new LinkedInUser("leia", null);

    user0.addConnection(user1);//Han gets 2 connections
    user0.addConnection(user2);

    List<LinkedInUser> friends = user0.getConnections();//Transfer to array
    Collections.sort(friends);//Sort

    Assert.assertEquals(user2, friends.get(0));//Compare
    Assert.assertEquals(user1, friends.get(1));
    }

1 Ответ

0 голосов
/ 23 января 2020

Похоже, вы сохраняете LinkedInUser в массиве несопоставленных типов.

ArrayStoreException в Java

ArrayStoreException in Java occurs whenever an attempt is made to store the wrong type of object into an array of objects. The ArrayStoreException is a class which extends RuntimeException, which means that it is an exception thrown at the runtime.

publi c Класс ArrayStoreException расширяет RuntimeException

Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates an ArrayStoreException:
     Object x[] = new String[3];
     x[0] = new Integer(0);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...