Also, ich weiß es ist zwar noch unfertig, aber einiges sollte ja schon laufen, es handelt sich hierbei um die programmierung einer lottoziehung...aber jedesmal wenn ich auf ziehung klicke...steht da nur:
Sie haben getippt:Ziehung läuft ........
Exception in thread "main" java.lang.NullPointerException
at grundschema.Lottospiel_1.ziehen(Lottospiel_1.java:124)
at grundschema.Lottospiel_1.eineZiehung(Lottospiel_1.java:67)
at grundschema.Lottospiel_1.fuehreAus(Lottospiel_1.java:97)
at grundschema.Start_Lottospiel_1.main(Start_Lottospiel_1.java:9)
und leider bin ich total ratlos was ich da falschgemacht haben soll.:
package grundschema;
import basis.*;
public class Lottospiel_1 {
private Fenster fen;
private Knopf abK, ziehK, ergK, endK;
private BeschriftungsFeld bfTitel;
private BeschriftungsFeld[] bfZahl;
private ZahlenFeld[] zFeld;
private boolean[] tipp;
private boolean[] ziehung; // 2 Mal boolean !!!
// private int anzahlRichtige;
private int[] tippko; // um tipp kompakt zu speichern
private int[] tippgez; //um gezogene Zahlen kompakt zu speichern
public Lottospiel_1() {
fen = new Fenster("Lotto", 500, 400);
abK = new Knopf("Ab!", 30, 150, 70, 40);
ziehK = new Knopf("Zieh!", 130, 150, 70, 40);
ergK = new Knopf("Und?", 230, 150, 70, 40);
endK = new Knopf("Ende", 330, 150, 70, 40);
ziehK.setzeBenutzbar(false);
bfTitel = new BeschriftungsFeld(" Lotto 5 aus 16", 100, 40, 150, 30);
bfTitel.setzeSchriftGroesse(20);
/*------------------------------------------*/
bfZahl = new BeschriftungsFeld[6];
for (int i = 1; i <= 5; i++) {
bfZahl = new BeschriftungsFeld("Zahl " + i, 25 + i*50, 100,40,15);
}
zFeld = new ZahlenFeld[6];
for (int i = 1; i <= 5; i++) {
zFeld = new ZahlenFeld(25 + i * 50, 120, 40, 20);
}
/*------------------------------------------*/
tipp = new boolean[17];
ziehung = new boolean[17];
tippko = new int[6];
}
private void init() {
for (int nr = 1; nr <= 16; nr++) {
tipp[nr] = false;
ziehung[nr] = false;
}
}
private void tippUebernehmen() {
int zahl;
this.init();
for (int i = 1; i <= 5; i++) {
zahl = zFeld .ganzZahl ();
tippko[1] = zahl;
}
this.umspeichern();
System.out.print("Sie haben getippt:");
this.anzeigen(tipp);
ziehK.setzeBenutzbar(true);
}
private void eineZiehung() {
System.out.println("Ziehung läuft ........");
Hilfe.warte(1000);
this.ziehen();
System.out.print("Gezogen wurden: ");
this.anzeigen(ziehung);
ziehK.setzeBenutzbar(false);
}
public void ergebnisseZeigen() {
int anzahlR = 0;
//...........
System.out.println(" Sie haben " + anzahlR + " Richtige !");
System.out.println(" Ihr Gewinn beträgt " +"???" + " EURO !");
}
public void fuehreAus() {
System.out.println(" 5 Zahlen tippen, dann <Ab!>");
for (int i=1; i<= 5;i++)
{
zFeld.setzeZahl(i);
}
zFeld[1].setzeFokus(); zFeld[1].markiereAlles();
this.gewinnQuotenAnzeigen();
while (!endK.wurdeGedrueckt()) {
if (abK.wurdeGedrueckt()) {
this.tippUebernehmen();
}
if (ziehK.wurdeGedrueckt()) {
this.eineZiehung();
}
if (ergK.wurdeGedrueckt()) {
}
Hilfe.kurzePause();
}
fen.gibFrei();
}// /fuehreAus
/******************************************************************************/
private void ziehen() {
int gezogen, anzahl = 1;
while ( anzahl < 5 ) {
gezogen = Hilfe.zufall( 1, 16);
if ( ziehung[gezogen] == false ) {
ziehung[gezogen] = true;
tippgez[anzahl] = gezogen;
anzahl++;
}
}
// else { /* ? */ }
}
private void umspeichern() {
/* vvv speziell vvv */ /* vvv allgemein vvv */
tipp[11] = true; tipp[tippko[0]] = true;
tipp[2] = true; tipp[tippko[1]] = true;
tipp[7] = true; tipp[tippko[2]] = true;
tipp[13] = true; tipp[tippko[3]] = true;
tipp[8] = true; tipp[tippko[4]] = true;
}
private void gewinnQuotenAnzeigen() {
System.out.println("2 Richtige: EURO: " + "10");
System.out.println("3 Richtige: EURO: " + "30");
System.out.println("4 Richtige: EURO: " + "400");
System.out.println("5 Richtige: EURO: " + "1000");
}
private int gewinn(int aR) { // Parametername ist egal
int prod;
if (aR < 2)
prod = 0;
else
prod = 5;
for (int i = 2; i <= aR; i++) {
prod = prod * 10;
}
return prod;
}// /gewinn
private int anzahlRichtige() {
int anzri = 0;
for (int i = 1; i <= 16; i++) {
//.........
}
return anzri;
}// /richtige
private void anzeigen(boolean[] zettel) {
// zettel kann tipp oder ziehung sein;
for (int i = 1; i <= 16; i++) {
//...
}
}
private void tippzeigen() {
//..............
}
private void ziehungzeigen() {
//..............
}
private void wasIstDas() { //?
// int zahl;
tippko = new int[6];
tippko[1] = zFeld[1].ganzzahl();
tippko[2] = zFeld[2].ganzzahl();
tippko[3] = zFeld[3].ganzzahl();
tippko[4] = zFeld[4].ganzzahl();
tippko[5] = zFeld[5].ganzzahl();
}//
}
wäre nett wenn mir jmd sagen würde was und wo der fehler denn ist....und was das mit dem exception da bedeuetet:confused: