P
P
pshevnin2021-12-03 00:01:19
Java
pshevnin, 2021-12-03 00:01:19

What is the problem with HashMap?

Good afternoon. There was a problem while writing a term paper in Java.
When accessing HashMap I get this error.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "pt.Kun.getId()" because "kun" is null
  at PT_semestralni/pt.Letoun.naplanujLet(Letoun.java:271)
  at PT_semestralni/pt.Simulace.spustSimulace(Simulace.java:33)
  at PT_semestralni/pt.Main.main(Main.java:32)

At the same time, on line 271, I output this to the console:
Kun kun = CteniDat.koneHashMap.get(idAktualnihoKone);
System.out.printf("Kun cislo: %d, Hmotnost: %d, X: %f \n",kun.getId(), kun.getHmotnost(), kun.getSourX());

And this text is successfully output to the console. That is, the "kun" object can no longer be NULL. Console text:
Kun cislo: 5, Hmotnost: 1000, X: 992229,190000

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacen11, 2021-12-03
@Jacen11

That is, the object "kun" can no longer be NULL

what are you talking about. Do you think this is some kind of bug in Java? language which is used by all banks for its reliability
What is the problem with HashMap?
you don’t even understand in anything
that calling methods or fields on any null object will be an exception
At the same time, on line 271, I output this to the console:

so what do you think the line number should say? In fact, it just says that you yourself don’t understand the sequence of execution of your code due to the size and complexity. Usually the average class size should be smaller

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question