Compiler-Fehler Exception in thread "main" java.lang.Error: Unresolved compilation problem:

Streetfive

Neues Mitglied
Hallo zusammen,

bin gerade erst im Einstieg mit der Sprache Java und versuche seit ne Stunde hier meinen Fehler zu erkennen.
Jedoch, bin ich gerade mit meinem Latein am ende und benötige hier bitte Unterstützung.

Anhand einer Aufgabestellung" Erstelle einen Kreis der grafisch dargestellt werden soll. Hierzu verwende ich seit mehreren Aufgaben die Klasse "kreis" sowie die Klasse "KreisApplikation".

Eigentlich, sollte jetzt ein Kreis auf dem Bildschirm dargestellt werden:rolleyes:. Jedoch erhalte ich die folgenden Fehlerhinweise:

Exception in thread "main" java.lang.NullPointerException


at Kreis.<init>(Kreis.java:37)
at KreisApplikation.<init>(KreisApplikation.java:17)
at KreisApplikation.main(KreisApplikation.java:32)


Meine Vermutung ist, dass ich irgendetwas an der Klasse drawOval noch initialisieren muss. Jedoch stehe ich gerade völlig auf dem Schlauch und meine Änderungen haben zu keinerlei Lösungsansätze herbeigeführt.

Wer kann mir bitte hierzu einen Tipp geben, damit ich auf den richtigen Lösungsweg komme?

Vielen Dank im Voraus.
Viele Grüße

Petro



Code von kreis:

Java:
public class Kreis extends Object 
{

public int x; // Mittelpunkt -x  Datentyp / Bezeichner/ WERT
public int y; // Mittelpunkt -y
public int radius;
public final double PI = 3.14159; // final Deklaration für die Konstante PI
private Kreis g;
private static int kreisZaehler = 0;
public Kreis()

{
    this (100, 100 ,50 );
}
public Kreis (int x, int y, int radius)
{
    
    this.x = x;
    this.y = y;
    this.radius = radius;
    kreisZaehler++;}

    
        public static int getkreisZaehler(){
        return kreisZaehler;
}
        
        public void zeichne (java.awt.Graphics g) {
        }
        
        public void drawOval (int x, int y, int width, int height) {
        }
        {
     [B]   [/B][COLOR=rgb(243, 121, 52)][B]g.drawOval(x-radius, y-radius, 2 * radius, 2 * radius);[/B][/COLOR]
        
    }

public int getX() { return x; }
public int getY() { return y; }
public int getRadius() { return radius; }
public double getFlaeche()
{
    return radius * radius * PI;
}
public double getUmfang()
{
    return 2 * radius * PI;
}
public void bewege(int deltaX, int deltaY)
{
    x += deltaX;
    y += deltaY;
}
public void skaliere(int deltaRadius)
{
    radius += deltaRadius;
}
public String toString()
{
    return "Kreis - Mittelpunkt "+x+"/"+y+", Radius "+radius;
}

    public boolean equals(Object obj)
        
    {
    
if(obj == null) {
    return false;
}
if (obj == this) {
    return false;
}
if (!(obj instanceof Kreis)){
    return false;
}
Kreis k =(Kreis)obj;
return k.x==x && k.y==y && k.radius == radius;

}       
}

Code von KreisApplikation:

Java:
import javax.swing.JFrame;
import javax.swing.JTextArea;

import java.awt.Graphics;

 public class KreisApplikation extends JFrame{
    
    
      JTextArea m_resultArea = new JTextArea(6, 30);
      private static final long serialVersionUID = 1L;
    
    
[COLOR=rgb(184, 49, 47)][B]    Kreis kreis;[/B][/COLOR]
    
    public KreisApplikation() {
        
        kreis = new Kreis(100,100,50);
        
        this.setSize (300,300); // Kreisobjekt initialisieren
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public void paint(Graphics g) {
        kreis.zeichne(g);
        
    }
    public static void main (String [] args) {
        

       [B][COLOR=rgb(65, 168, 95)] new KreisApplikation().setVisible(true);[/COLOR][/B]
        
        
    }
    
}
 
X

Xyz1

Gast
Probier das ma:
Java:
public class Kreis extends Object {

	public int x; // Mittelpunkt -x Datentyp / Bezeichner/ WERT
	public int y; // Mittelpunkt -y
	public int radius;
	public final double PI = 3.14159; // final Deklaration für die Konstante PI

	private static int kreisZaehler = 0;

	public Kreis()

	{
		this(100, 100, 50);
	}

	public Kreis(int x, int y, int radius) {

		this.x = x;
		this.y = y;
		this.radius = radius;
		kreisZaehler++;
	}

	public static int getkreisZaehler() {
		return kreisZaehler;
	}

	public void zeichne(java.awt.Graphics g) {
		g.drawOval(x - radius, y - radius, 2 * radius, 2 * radius);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getRadius() {
		return radius;
	}

	public double getFlaeche() {
		return radius * radius * PI;
	}

	public double getUmfang() {
		return 2 * radius * PI;
	}

	public void bewege(int deltaX, int deltaY) {
		x += deltaX;
		y += deltaY;
	}

	public void skaliere(int deltaRadius) {
		radius += deltaRadius;
	}

	public String toString() {
		return "Kreis - Mittelpunkt " + x + "/" + y + ", Radius " + radius;
	}

	public boolean equals(Object obj)

	{

		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return false;
		}
		if (!(obj instanceof Kreis)) {
			return false;
		}
		Kreis k = (Kreis) obj;
		return k.x == x && k.y == y && k.radius == radius;

	}
}


Kreis sollte nicht nochmal eine Variabel Kreis haben (riecht verdächtig nach NPE) und setVisible brauchst Du nur einmal aufrufen (im Konstruktor).
 
X

Xyz1

Gast
Ich helfe wo ich kann. (dennoch will keiner feiern wenn ich eine Schnapszahlbeiträge habe) :eek:
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
F Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at main.main(main.java:11) Java Basics - Anfänger-Themen 2
M Exception in thread "main" java.util.NoSuchElementException Java Basics - Anfänger-Themen 2
O Exception in thread "main" java.lang.ArithmeticException: / by zero Java Basics - Anfänger-Themen 4
R Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 5
I Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 Java Basics - Anfänger-Themen 3
R Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 10
C Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 Java Basics - Anfänger-Themen 3
J Exception in thread "main" Java Basics - Anfänger-Themen 1
L Fehler: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 4
N Threads Exception in thread "main"... Feher bei dem Versuch ein Radius zu berechnen Java Basics - Anfänger-Themen 4
A Code läuft nicht, Fehlermeldung Exception in thread "main" java.lang.Error: Unresolved compilation " Java Basics - Anfänger-Themen 11
P Exception in thread "main" java.lang.NoClassDefFoundError: Java Basics - Anfänger-Themen 1
K Exception in thread "main" Java Basics - Anfänger-Themen 7
L Compiler-Fehler Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 2
F Exception in thread main java.lang.StackOverflowError Java Basics - Anfänger-Themen 3
A Compiler-Fehler Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 7
T Problem mit Eclipse? Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 4
M Exception in thread "main" java.lang.NoClassDefFoundError: MeineKlasse Java Basics - Anfänger-Themen 12
S Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 11
S Umgebungsvariable Exception in thread "main" java.lang.UnsatisfiedLinkError: no J3D in java.librar y.path Java Basics - Anfänger-Themen 15
M Klassen Exception in thread "main" java.lang.NoClassDefFoundError: Java Basics - Anfänger-Themen 2
D Exception in thread "main" Java Basics - Anfänger-Themen 8
A Exception in thread "main" Java Basics - Anfänger-Themen 7
S Exception in thread "main" Java Basics - Anfänger-Themen 3
B Exception in thread "main" java.lang.NullPointerException Fehler Hilfe! Java Basics - Anfänger-Themen 4
L Bubblesort: Exception in Thread "main" Java Basics - Anfänger-Themen 5
A Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 16
A GELÖST -- Exception in thread "main" Java Basics - Anfänger-Themen 3
B Fehlermeldung - Exception in thread "main" java.lang.Error: Unresolved compilation pr Java Basics - Anfänger-Themen 16
E Fehler: "Exception in thread "main" java.lang.NoSuchMethodError" Java Basics - Anfänger-Themen 15
G Fehler: Exception in thread main java.lang.noClassDefFound Java Basics - Anfänger-Themen 7
L Exception in thread "main" java.util.NoSuchElement Java Basics - Anfänger-Themen 4
A Do/While Problem (Exception in thread "main" java. Java Basics - Anfänger-Themen 4
M "exception in thread "main" java.lang.NullPoi Java Basics - Anfänger-Themen 2
S Exception in thread "main" java.lang.UnsupportedCl Java Basics - Anfänger-Themen 4
P Exception in thread "main" Java Basics - Anfänger-Themen 4
V Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 21
S Exception in thread "main" java.lang.NoSuchMethodE Java Basics - Anfänger-Themen 3
NightmareVirus Exception in thread "main" java.lang.NoSuchMethodE Java Basics - Anfänger-Themen 8
A "Exception in thread "main" java.lang.NoCLass Java Basics - Anfänger-Themen 10
N exception in thread main . Java Basics - Anfänger-Themen 3
C Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 9
vogella Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 4
R Exception in thread "main" java.lang.NoSuchMethodE Java Basics - Anfänger-Themen 6
C exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 7
A Fehlermeldung: Exception in thread "main" java.lan Java Basics - Anfänger-Themen 3
H Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 3
R Exception in Thread "main" . Kommandozeile/Netbean Java Basics - Anfänger-Themen 8
L Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 4
R Exception in thread "main" java.lang.NullPointerEx Java Basics - Anfänger-Themen 10
B Exception in thread "main"... Java Basics - Anfänger-Themen 3
L Exception in thread "main" java.lang.NoSuchMethodE Java Basics - Anfänger-Themen 3
K Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 8
J Exception in thread "main" java.langClassNoFoundEr Java Basics - Anfänger-Themen 2
H Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 5
B Fehler: Exception in Thread "main" java.lang.NoCla Java Basics - Anfänger-Themen 2
G Exception in thread "main" java.lang.NoClassDefFou Java Basics - Anfänger-Themen 2
B Compiler-Fehler Fehlermeldung Exception in thread, falsche Eingabewert Java Basics - Anfänger-Themen 2
S Kriege Fehler "Exception in thread" beim Benutzen von SubStrings. Java Basics - Anfänger-Themen 2
B Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException Java Basics - Anfänger-Themen 8
S Java memory fehler: Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa Java Basics - Anfänger-Themen 5
V Threads Exception in Thread behandeln Java Basics - Anfänger-Themen 3
D Exception in thread "AWT-EventQueue-0" Java Basics - Anfänger-Themen 8
C Exception in thread "AWT-EventQueue-0 Java Basics - Anfänger-Themen 15
M Exception in thread "AWT-EventQueue-0" Java Basics - Anfänger-Themen 7
1 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Java Basics - Anfänger-Themen 5
A Exception aus Thread werfen Java Basics - Anfänger-Themen 14
J Datentypen Exception in thread "AWT-EventQueue-0"?? Java Basics - Anfänger-Themen 4
T Thread 2x starten verursacht Exception Java Basics - Anfänger-Themen 3
Y Exception in thread Java Basics - Anfänger-Themen 11
Spin Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: data must Java Basics - Anfänger-Themen 10
O java.lang.NoClassDefFoundError Exception in thread "mai Java Basics - Anfänger-Themen 5
S Exception in thread Java Basics - Anfänger-Themen 7
A Exception in thread "Thread-33" java.lang.NoClassD Java Basics - Anfänger-Themen 10
F Fehlermeldung: Exception in thread. Java Basics - Anfänger-Themen 17
G Exception in thread Java Basics - Anfänger-Themen 9
H exception in thread mainjava.lang.noclass ... Java Basics - Anfänger-Themen 3
I Exception wird gefangen, aber trotzdem in Error Log? Java Basics - Anfänger-Themen 10
W Null-Pointer Exception beim Programmstart Java Basics - Anfänger-Themen 8
Ostkreuz String Exception Java Basics - Anfänger-Themen 8
Fiedelbambu Exception in Application constructor Java Basics - Anfänger-Themen 3
S leeres Array statt Null Pointer Exception ausgeben Java Basics - Anfänger-Themen 20
F abbruch Exception lässt sich nicht erstellen Java Basics - Anfänger-Themen 2
U Warum kriege ich hier eine nullpointer exception, sehe den Fehler nicht (swing) Java Basics - Anfänger-Themen 1
N Exception beim Verwenden von Arraylist? Java Basics - Anfänger-Themen 10
S JavaKara Null Exception Error Java Basics - Anfänger-Themen 4
T Eigene Exception - ohne werfen abfangen Java Basics - Anfänger-Themen 2
LiFunk Exception: es dürfen nur Nummern eingelesen werden Java Basics - Anfänger-Themen 6
low_in_the_head Eigene Exception nutzen Java Basics - Anfänger-Themen 4
1 Exception Java Basics - Anfänger-Themen 2
I JAX-RS Exception Handling Java Basics - Anfänger-Themen 4
L Meine erste eigene Exception Klasse Java Basics - Anfänger-Themen 10
J null exception Array Java Basics - Anfänger-Themen 5
H Frage zu Throw Exception Java Basics - Anfänger-Themen 2
M Wie kann ich bei int-Variablen im exception handler auf bestimmte Strings reagieren? Java Basics - Anfänger-Themen 5
C Exception-Frage Java Basics - Anfänger-Themen 3
I Exception bei Button mit wait() und notifyAll() Java Basics - Anfänger-Themen 3
N Wie teste ich eine geworfene Exception? Java Basics - Anfänger-Themen 8
R Methoden ArrayList clonen wirft exception Java Basics - Anfänger-Themen 3
D Scanner- Exception NoSuchElementException Java Basics - Anfänger-Themen 2

Ähnliche Java Themen

Neue Themen


Oben