java.lang.NullPointerException
at com.javarush.task.task07.task0726.Solution.main(Solution.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.javarush.task.common.model.execution.ExecuteService.callMainMethod(ExecuteService.java:78)
at com.javarush.task.common.model.execution.ExecuteService.execute(ExecuteService.java:102)
at com.javarush.task.app.execution.ExecutionService.execute(ExecutionService.java:110)
at com.javarush.task.app.execution.ExecutionService.main(ExecutionService.java:254)
at com.javarush.task.app.MainApplication.main(MainApplication.java:49)
a esli zakommentirovat` proverku "isEmpty", to vivodit:
com/javarush/task/task07/task0726/Solution.java:31: error: unreachable statement
printList();
^
package com.javarush.task.task07.task0726;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Не компилируется задача про котиков
*/
public class Solution {
public final static ArrayList<Cat> CATS = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String name = reader.readLine();
// if (name.isEmpty()) break;
int age = Integer.parseInt(reader.readLine());
int weight = Integer.parseInt(reader.readLine());
int tailLength = Integer.parseInt(reader.readLine());
Cat cat = new Cat(name, age, weight, tailLength);
CATS.add(cat);
}
printList();
}
public static void printList() {
for (int i = 0; i < CATS.size(); i++) {
System.out.println(CATS.get(i));
}
}
public static class Cat {
private String name;
private int age;
private int weight;
private int tailLength;
Cat(String name, int age, int weight, int tailLength) {
this.name = name;
this.age = age;
this.weight = weight;
this.tailLength = tailLength;
}
@Override
public String toString() {
return "Cat name is " + name + ", age is " + age + ", weight is " + weight + ", tail = " + tailLength;
}
}
}