Swing Exception in thread "AWT-EventQueue-0"

Diskutiere Exception in thread "AWT-EventQueue-0" im AWT, Swing, JavaFX & SWT Bereich.
A

absoblume

Compiler gibt ununterbrochen folgende Fehlermeldung aus:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at break_out.view.Field.drawPaddleBottom(Field.java:133)
at break_out.view.Field.paintComponent(Field.java:101)
at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)
at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5255)
at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1643)
at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1618)
at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1556)
at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1323)
at java.desktop/javax.swing.JComponent._paintImmediately(JComponent.java:5203)
at java.desktop/javax.swing.JComponent.paintImmediately(JComponent.java:5013)
at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:865)
at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:848)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:848)
at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:823)
at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:772)
at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1884)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Ich finde den Fehler einfach nicht. :(
Würde mich über jede Hilfe freuen.

Danke!

Code:
//Klasse Field

private void drawPaddleTop(Graphics2D g2){
        g2.fillRoundRect((int) view.getGame().getLevel().getPaddleTop().getPosition().getY(),
                         (int) view.getGame().getLevel().getPaddleTop().getPosition().getX(),
                Constants.PADDLE_HEIGHT,
                Constants.PADDLE_WIDTH,
                50,25);
    }

    private void drawPaddleBottom(Graphics2D g2){
        g2.fillRoundRect((int) view.getGame().getLevel().getPaddleBottom().getPosition().getY(),
                (int) view.getGame().getLevel().getPaddleBottom().getPosition().getX(),
                Constants.PADDLE_HEIGHT,
                Constants.PADDLE_WIDTH,
                50,25);
    }
Code:
//Klasse Level

    private Paddle paddleTop;
    private Paddle paddleBottom;


    @Override
    public Paddle getPaddleTop() {
        return this.paddleTop;
    }

    public void setPaddleTop(Position position){
        Position PaddleTop = new Position(Constants.SCREEN_HEIGHT/2, Constants.SCREEN_WIDTH/2);
    }


    @Override
    public Paddle getPaddleBottom() {
        return this.paddleBottom;
    }
    public void setPaddleBottom(Position position){
        Position PaddleBottom = new Position(Constants.SCREEN_HEIGHT/2, Constants.SCREEN_WIDTH/2);
    }
Code:
//Klasse Paddle

public Paddle(Position position) {
        this.position = new Position(Constants.SCREEN_WIDTH/2, Constants.SCREEN_HEIGHT/2);

    }
    
    private Position position;
    private int Width;
    private int Height;
    private Color color;

    @Override
    public Position getPosition() {
        return null;
    }

    @Override
    public void setPosition(Position position) {
        // TODO Auto-generated method stub

    }

    @Override
    public Color getColor() {
        // TODO Auto-generated method stub
        return this.color;
    }

    @Override
    public void setColor(Color color) {
        // TODO Auto-generated method stub
        color = Color.WHITE;
    }

    @Override
    public int getWidth() {

        return this.Width;
    }

    @Override
    public void setWidth(int width) {

        Constants.PADDLE_WIDTH = this.Width;
    }

    @Override
    public int getHeight() {

        return this.Height;
    }

    @Override
    public void setHeight(int height) {

        Constants.PADDLE_HEIGHT = this.Height;
    }
}
Code:
//Klasse Constants


    public static Integer PADDLE_WIDTH = 70;

    public static Integer PADDLE_HEIGHT = 15;
 
H

httpdigest

Erstmal ist das kein Compilerfehler (also kein Fehler zur Compilezeit/Programmübersetzungszeit) sondern ein Laufzeitfehler (also ein Fehler, der erst zur Laufzeit des Programmes auftritt).
Desweiteren brauchst du einfach nur die Exception-Nachricht und den sogenannten Stacktrace zu lesen.

1. "java.lang.NullPointerException" bedeutet, dass auf eine Referenzvariable zugegriffen wurde, die "null" (also z.B. nicht initialisiert ist)
2. "at break_out.view.Field.drawPaddleBottom(Field.java:133)" bedeutet, dass der fehlerhafte Zugriff in Zeile 133 innerhalb der Datei Field.java in der Methode "drawPaddleBottom" passiert ist.

Schaue dir einfach diese Zeile an und prüfe, welche der vielen verketteten Methodenaufrufe "null" produzieren könnte. Ein Debugger hilft hier auch!

Wahrscheinlich ist irgend ein Wert in dieser Kette "null":
`view.getGame().getLevel().getPaddleTop().getPosition()`
 
Thema: 

Exception in thread "AWT-EventQueue-0"

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben