Big time Error

1 resposta
coxaqui

Ola, Primeiro post aqui, desculpem qualquer coisa mas aqui esta.

Dei uma olhadanos noutros posts mas nao consequi resolver esse erro.

Compila beleza mas quando executo usando o "w" e "h" do metodo "read" naum funcione e recebo erro:

"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0"

mas se seto "w" e "h" em "main" executa tambem beleza, o erro provavelmente esta no metodo "read" mas naum consigo achar, por favor ajudem me... :lol:

import java.io.*;
import java.util.*;

public class MazeFirst
{
	static int h, w;
	static Random fill = new Random();
	
	public static void displayArray(int[][] array, int h, int w) //mostra a array
	{   
		for(int j = 0; j < h; j++)
		{
			{
				for(int y = 0; y < w; y++)
				{
					System.out.print(array[j][y] + " ");
				}
				System.out.println("\n");
			}
			
		}
	}
	public static void wallFilling(int[][] array, int h, int w) //preenche a array com zeros
	{
		for(int j = 0; j < h; j++)
		{
			for(int y = 0; y < w; y++)
			{
				array[j][y] = 0; 
				//System.out.println(array[j][y] + " ");
			}
		}
		
	}
	
	

    static public void read()   // ******leio aqui*****erro provavelmente aqui
    {
    		try{
    // Open the file that is the first 
    // command line parameter
    FileInputStream fstream = new FileInputStream("MAZEFILE.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    
    //Read first line
    w = Integer.parseInt(br.readLine());  // ******tudo parece estar blz
    h = Integer.parseInt(br.readLine());  	
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) 
    {
    	
      // Print the content on the console
      System.out.println (strLine);
    }
    
    //Close the input stream
   //in.close();
    }
    catch (Exception e)
    {//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  
		
    }
    
    
   public static void main(String args[])
   {
   //	w =50;
   //	h =50;
   	 int[][] a = new int[h][w];
   	//draw();
   	read();   //  Leio de um arguivo contendo apenas 2 linhas(50, 50)
   	wallFilling(a, h,w);
   	displayArray(a, h, w);
   	
   	System.out.println(" Width = "+w+" Height = " + h);
   }
    
}

1 Resposta

coxaqui

alguem por fovor!!!
O que eu fiz de erradoooo

Criado 1 de junho de 2007
Ultima resposta 2 de jun. de 2007
Respostas 1
Participantes 1