Hi.
I think that there is error in task. I did all of it as it should be done, IDEA shows that code is correct but somehow the website shows errors:
java.lang.NullPointerException
at pl.codegym.task.task08.task0821.Solution.printListLudzi(Solution.java:33)
at pl.codegym.task.task08.task0821.Solution.main(Solution.java:13)
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)
The only thing i did is:
Map<String, String> mapa1 = new HashMap<String, String>();
mapa1.put("anna", "mrok");
mapa1.put("baba", "vfdfdf");
mapa1.put("eqwa", "mbuspoa");
mapa1.put("yrasa", "mdksapa");
mapa1.put("bvcsad", "mrok");
mapa1.put("anna", "odsajmdsa");
mapa1.put("ytrfd", "mdsadop");
mapa1.put("vcsa", "mdsmalas");
mapa1.put("ajhgyua", "mrok");
mapa1.put("anna", "vsdsadsa");
I haven't changed any of the code before or after these lines.
Please tell me what is wrong. Thanks
package pl.codegym.task.task08.task0821;
import java.util.HashMap;
import java.util.Map;
/*
Współdzielone nazwiska i imiona
*/
public class Solution {
public static void main(String[] args) {
Map<String, String> mapa = utworzListLudzi();
printListLudzi(mapa);
}
public static Map<String, String> utworzListLudzi() {
Map<String, String> mapa1 = new HashMap<String, String>();
mapa1.put("anna", "mrok");
mapa1.put("baba", "vfdfdf");
mapa1.put("eqwa", "mbuspoa");
mapa1.put("yrasa", "mdksapa");
mapa1.put("bvcsad", "mrok");
mapa1.put("anna", "odsajmdsa");
mapa1.put("ytrfd", "mdsadop");
mapa1.put("vcsa", "mdsmalas");
mapa1.put("ajhgyua", "mrok");
mapa1.put("anna", "vsdsadsa");
return null;
}
public static void printListLudzi(Map<String, String> mapa) {
for (Map.Entry<String, String> s : mapa.entrySet()) {
System.out.println(s.getKey() + " " + s.getValue());
}
}
}