0
votes
object = new Object(int something);
for(int i=0;i<5;i++) {
    //obj=queue.element();
    obj=queue.remove();
    object=obj.runTasks(int somethingElse);
    queue.offer(obj);
    //queue.remove();
}

I'm basically trying to use the methods of the object first in the queue, then put it in the back of the queue, and use the next object, and put that one last in the queue, etc.

The line object=obj.runTasks(int...) causes the program to terminate, with a lot of warnings, for example "Exception in thread "AWT-EventQueue-0".

Also these:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at projekt.Modell.körSaker(Modell.java:110)
    at projekt.Controller$CloseListener.actionPerformed(Controller.java:84)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Does anyone have a solution? Thanks!

2
the code you pasted doesn't even compile. What is Object. What is on line 84 of Controller.java. - Bozho
Obviously I didn't add the entire code. The line 84 of Controller.java calls the method that contains the code above. Modell.java:110 is object=obj.runTasks(int somethingElse). I just thought I'd make it easier to read than if it contained my variables. - Rickard

2 Answers

1
votes

Assertions can help debug this kind of problem. If you expect all elements in the queue to be null, then consider using code like this:

obj=queue.remove();
assert(obj != null);
object=obj.runTasks(int somethingElse);

If you pull a null object out of the queue, which is unexpected, the program will die on the assert. The cause of the problem is often much clearer, when assertions are in place.

You'll have to run with -ea to enable assertions. See http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html

0
votes

I finally solved it. I was filling the queue with some null objects, and some non-null objects, which made it harder to realize.