Так я пытаюсь добавить элементы (которые должны быть статическими) к ArrayList с помощью этого шаблона класса: AllEventInformationStatic.java:Добавление элементов в ArrayList в цикле
public class AllEventInformationStatic {
public static int id;
public static String name;
public static String type;
public static String date;
public static String desc;
public static String location;
public AllEventInformationStatic(int id, String name, String type, String date, String desc, String location)
{
AllEventInformationStatic.id = id;
AllEventInformationStatic.name = name;
AllEventInformationStatic.type = type;
AllEventInformationStatic.date = date;
AllEventInformationStatic.desc = desc;
AllEventInformationStatic.location = location;
}
}
AllEventResponseStatic.java:
public class AllEventResponseStatic {
public static ArrayList<AllEventInformationStatic> events;
}
А вот итерация для заполнения ArrayList:
AllEventResponseStatic.events = new ArrayList<AllEventInformationStatic>();
for (int i = 0; i < allEventResponse.events.size(); i++)
{
AllEventResponseStatic.events.
add(new AllEventInformationStatic(42, "bowling",
"event", "11/12/2015",
"enjoy it", "paris"));
String name = AllEventResponseStatic.events.get(0).name;
}
String name_bis = AllEventResponseStatic.events.get(0).name;
Таким образом, имя переменной отображается «боулинг», но name_bis - Null. кажется, что он просто очистил весь аррайалист после итерации, и я не знаю, почему ..
Если у вас есть идеи, где проблема?
Просто дважды проверьте, что вы знаете, в чем разница между объявлением переменной как 'static' и не выполняющей ее. – alfasin
Пожалуйста, покажите фактический код. Нет никакого способа, чтобы то, что вы опубликовали, даст результат, который вы описываете (также, как и ожидалось для меня, когда я вставляю ваш код в eclipse). – azurefrog
Но я должен был объявить переменную как статическую, чтобы получить их из другого класса, так как мне это делать? – Chris