I keep getting a null pointer exception when trying to add an object to the priority queue
i initialize the queue:
private PriorityQueue<NodeObject> nodes;
and here I am trying to add to it:
NodeObject childNode = new NodeObject(child, 1); nodes.add(childNode);
why doesn't it work? I know that my NodeObject is not null because I create it right before I add it.
You did not initialize the queue.
nodes = new SomePriorityQueue();
The problem is that you forgot to initialize the priority queue nodes. Change it to:
nodes
private PriorityQueue<NodeObject> nodes = new PriorityQueue<NodeObject>();
nodes ( nodes = new PriorityQueue<NodeObject>();) . , Java , , , , nodes null, , -.
nodes = new PriorityQueue<NodeObject>();
null
; nodes == null. NullPointerException nodes.add.
nodes == null
NullPointerException
nodes.add
- PriorityQueue<NodeObject> nodes. :
PriorityQueue<NodeObject>
private PriorityQueue<NodeObject> nodes = new PriorityQueue<NodeObject>(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
, :null.
Source: https://habr.com/ru/post/1742923/More articles:Есть ли такая вещь, как обратный CDN? (сеть поиска контента) - cloud-hostingHow to remove duplicate characters, but leave two of them? - stringprocess all links except external (ruby + mechanize) - ruby | fooobar.comto create a class immediately after the property field? - oopHello Guest - multithreadingEnhanced functionality in Enum - enumsКомпоненты Coldfusion: - аргумент, переданный функции, не имеет тип numeric - coldfusionзахват пакетов dns с использованием java - java'if' block in IL - .netHow to create a modeless dialog in Perl / Tk? - perlAll Articles