Foros del Web » Programación para mayores de 30 ;) » Java »

Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1.JPG

Estas en el tema de Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1.JPG en el foro de Java en Foros del Web. import java.io.*; //import java.util.Stack; class MazeCell { public int x, y; public MazeCell(){ } public MazeCell(int i, int j){ x= i; y=j; } public boolean ...
  #1 (permalink)  
Antiguo 11/03/2009, 20:53
fdaf58
Invitado
 
Mensajes: n/a
Puntos:
Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1.JPG

import java.io.*;
//import java.util.Stack;


class MazeCell {
public int x, y;
public MazeCell(){
}
public MazeCell(int i, int j){
x= i; y=j;
}
public boolean equals(MazeCell cell){
return x == cell.x && y == cell.y;
}
}
class Maze{
private int rows = 0, cols = 0;
private char[][] store;
private MazeCell currentCell, exitCell =
new MazeCell(), entryCell = new MazeCell();
private final char exitMarker = 's', entryMarker = 'e', visited = '.';
private final char passage = '0', wall = '1';
private java.util.Stack mazeStack = new java.util.Stack();
public Maze() {
int row = 0, col = 0;
java.util.Stack mazeRows = new java.util.Stack();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader buffer = new BufferedReader(isr);
System.out.println("Introduzca un laberinto rectangular utilizando los caracteres "
+"siguientes:\ne - entrada\ns - salida\n1 - muro\n0 - pasillo\n"
+"introduzca una linea a la vez; termine con Ctrl-z: ");
try {
String str = buffer.readLine();
while (str != null){
row++;
cols = str.length();
str = "1" + str + "1"; //pone 1 en las celdas del borde;
mazeRows.push(str);
if (str.indexOf(exitMarker) != -1){
exitCell.x = row;
exitCell.y = str.indexOf(exitMarker);
}
if (str.indexOf(entryMarker) != -1) {
entryCell.x = row;
entryCell.y = str.indexOf(entryMarker);
}
str= buffer.readLine();
}
}catch(IOException eof){
rows = row;
store = new char[rows+2][]; //crea un arreglo ID de arreglos char;
store[0] = new char[cols+2]; //una fila de borde;
for (; !mazeRows.isEmpty();row--)
store[row] = ((String) mazeRows.pop()).toCharArray();
store[rows+1] = new char[cols+2]; //otro fila de borde;
for (col = 0; col <= cols+1;col++){
store[0][col]=wall; // llena las filas de borde con 1;
store[rows+1][col]=wall;
}
}
}
private void display(PrintStream out){
for (int row = 0;row <= rows+1;row++)
System.out.println(store[row]);
System.out.println();
}
private void pushUnvisited(int row, int col){
if (store[row][col] == passage || store[row][col]==exitMarker)
mazeStack.push(new MazeCell(row,col));
}
public void exitMaze(PrintStream out){
currentCell = entryCell;
out.println();
while (!currentCell.equals(exitCell)){
int row = currentCell.x;
int col = currentCell.y;
display(System.out); //imprime una imagen instantanea;
if (!currentCell.equals((entryCell)))
store[row][col] = visited;
pushUnvisited(row-1, col);
pushUnvisited(row+1, col);
pushUnvisited(row, col-1);
pushUnvisited(row, col+1);
if (mazeStack.isEmpty()){
display(out);
out.print("Intento fallido");
return;
}
else currentCell = (MazeCell) mazeStack.pop();
}
display(out);
out.print("Intento exitoso");
}
public static void main (String args[]){
(new Maze()).exitMaze(System.out);
}
}

Disculpen no se porque motivo me salen esas excepciones, agradeceria si me pueden ayudar.
el link de la imagen esta en el titulo
  #2 (permalink)  
Antiguo 12/03/2009, 09:36
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1

Mensaje movido al foro de Java desde Bienvenida a Foros del Web.

Saludos,
  #3 (permalink)  
Antiguo 12/03/2009, 10:57
Avatar de chuidiang
Colaborador
 
Fecha de Ingreso: octubre-2004
Mensajes: 3.774
Antigüedad: 19 años, 6 meses
Puntos: 454
Respuesta: Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1

¿Cual es la línea 64 del fichero Maze.java? Esa es la que está lanzando la excepción. Ese tipo de excepciones se da si llamas a un método de algo que es null, por ejemplo

unaVariable.unMetodo()

siendo unaVariable null

Se bueno.
__________________
Apuntes Java
Wiki de Programación
  #4 (permalink)  
Antiguo 12/03/2009, 12:18
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Exception in thread "main" java.lang.Null http://mx.geocities.com/fdaf58/1

La línea es el println de:
Código java:
Ver original
  1. for (int row = 0;row <= rows+1;row++)
  2.     System.out.println(store[row]);
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:52.