Je ne comprends pas les erreurs

Fermé
ciarawom Messages postés 2 Date d'inscription samedi 15 juin 2013 Statut Membre Dernière intervention 16 juin 2013 - 15 juin 2013 à 17:07
KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 - 15 juin 2013 à 17:16
voici mon programme:
package fr.emse.simulator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

import fr.emse.simulator.gui.MapFrame;

public class Simulateur extends Simulator {
private MapFrame frame;
private World newWorld;
private boolean end = false;
FileReader fileReader;
BufferedReader reader;
public void loadMap(File file){


try{
FileReader fileReader = new FileReader(file);

BufferedReader reader = new BufferedReader(fileReader);


String[] line = reader.readLine().split(" ");
FireFighter.Health= Integer.parseInt(line[0]);
Pyromane.Health= Integer.parseInt(line[1]);
Pyromane.movingDelay=Integer.parseInt(line[2]);
Pyromane.lighterReload=Integer.parseInt(line[3]);
int a=Integer.parseInt(line[4]);
Pyromane.nbCellsDeath=a;
FireFighter.nbCellsDeath=a;
Typecase.progF=Integer.parseInt(line[5]);
Typecase.progP=Integer.parseInt(line[6]);
Typecase.exF=Integer.parseInt(line[7]);
Typecase.exP=Integer.parseInt(line[8]);

String[] line0 = reader.readLine().split(" ");
World.row=Integer.parseInt(line0[0]);
World.col=Integer.parseInt(line0[1]);
frame = new MapFrame(newWorld);



int i;
int j;

for(j=1;j<=World.row;j++)
{String[] linej = reader.readLine().split(" ");
for(i=0;i<World.col;i++)
{
World.wcell[i][j].type =(linej[i]);
}
line = reader.readLine().split(" ");
}


while (reader.ready()){
String[] line2 = reader.readLine().split(" ");
int x = Integer.parseInt(line2[0]);
int y = Integer.parseInt(line2[1]);
Pyromane p = new Pyromane(x, y,Pyromane.Health, Pyromane.nbCellsDeath, Pyromane.movingDelay, Pyromane.lighterReload);
World.ListPyro.add(p); ;
}

String[] line3 = reader.readLine().split(" ");


while (reader.ready()){
int x = Integer.parseInt(line3[0]);
int y = Integer.parseInt(line3[1]);
FireFighter fi= new FireFighter(x, y, FireFighter.Health, FireFighter.nbCellsDeath) ;
World.Listfire.add(fi); }
System.out.println();


reader.close();
fileReader.close();
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e)
{ e.printStackTrace();
}
}





public Simulateur(File file) {

super(file);
}


public void run(){

};
public void runOneStep(){

};

public boolean isOver() {
boolean end = false;
if(end==false)
return false;
else
return true;
}




public static void main(String[] args) {
World monde = null ;

File myFile = new File(args[0]);
Simulateur simulator= new Simulateur(myFile);
MapFrame frame = new MapFrame(monde);
frame.repaint(50);

System.out.println(FireFighter.Health);
}











}





et voici les erreurs
Exception in thread "main" java.lang.NullPointerException: IMPORTANT : you pass a null parameter for your simulation map : instanciated one new object!
at fr.emse.simulator.gui.MapPanel.<init>(MapPanel.java:53)
at fr.emse.simulator.gui.MapFrame.getMapPanel(MapFrame.java:50)
at fr.emse.simulator.gui.MapFrame.initMapPanel(MapFrame.java:60)
at fr.emse.simulator.gui.MapFrame.<init>(MapFrame.java:40)
at fr.emse.simulator.Simulateur.loadMap(Simulateur.java:43)
at fr.emse.simulator.Simulator.<init>(Simulator.java:32)
at fr.emse.simulator.Simulateur.<init>(Simulateur.java:94)
at fr.emse.simulator.Simulateur.main(Simulateur.java:120)
je ne comprends absolument pas c'est quoi ces erreurs

1 réponse

KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015
15 juin 2013 à 17:16
C'est pourtant écrit noir sur blanc :

"you pass a null parameter for your simulation map : instanciated one new object!
at fr.emse.simulator.Simulateur.main(Simulateur.java:120)"


Et quand on regarde ton main, ligne 120 de Simulateur.java, on a :
MapFrame frame = new MapFrame(monde);

Or, monde est déclaré un peu plus haut et sans surprise sa valeur est null, d'où le message d'erreur :
World monde = null ;

Il faut donc suivre les explications qui te sont donné, et instancier un nouvel objet World avant de le passer en paramètre de ta MapFrame.
1