![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Here's all of it. The error occurs on the same line as the above code.
Edit* now in red class FileRead
{
int xPieceSize, yPieceSize, xGridSize, yGridSize;
int totalPieces;
int fileCount;
Piece tetPiece [];
String fileData [];
public FileRead ()
{
int fileCount = 0;
int xPieceSize = 0, yPieceSize = 0, xGridSize = 0, yGridSize = 0;
int totalPieces = 0; // we must search through the file to know how many pieces are in the file.
//String fileData [] = new String []; // we use the size of the file to make an array of the specified size
//int PieceData[][][] = new int [totalPieces][xPieceSize][yPieceSize];
String str = "";
try
{
String temp = "";
BufferedReader in = new BufferedReader (new FileReader ("PieceData1.txt"));
// gets size of file -> so that we know how big to make the array that holds the file
while ((temp = in.readLine ()) != null)
{
fileCount = fileCount + 1;
}
in.close ();
System.out.print ("Size of file is: " + fileCount);
// size of file has been stored
// we use the size of the file to make an array of the specified to size of the file
String fileData [] = new String [fileCount];
in = new BufferedReader (new FileReader ("PieceData1.txt"));
for (int i = 0 ; i < fileCount ; i++) //
{
fileData [i] = in.readLine ();
}
in.close ();
}
catch (IOException e)
{
}
}
void updateGridSize ()
{
int tempLength;
int position = 0;
int marker = -1; // a negative value so we know it's not anywhere in the file by default
SearchForGrid: // a label
for (int m = 0 ; m < fileCount ; m++)
{
tempLength = fileData [m].length ();
position = fileData [m].indexOf ("<GridSize>");
if (position >= 0) // if strings not found, returns negative. Thus, if found it's (> 0)
{
marker = m; // holds place where grid is found
m++; // we have nothing else to do on this line
break SearchForGrid; // done looking for grid
}
}
String tempString = new String ("");
boolean blnXFound = false, blnYFound = false;
SearchGridSize:
for (int i = marker ; i < fileCount ; i++)
{
System.out.println ("position: " + fileData [i].indexOf ("<GPieceSize>"));
position = fileData [i].indexOf ("<GPieceSize>");
// if we passed onto the other tag, exit
if (position >= 0)
{
System.out.println ("Check your file (PieceData.txt), Somethings not right in there. Quit right now.");
break SearchGridSize;
}
position = fileData [i].indexOf ("x=");
if (position >= 0)
{
tempLength = fileData [i].length (); // takes lenght so we know where string ends
for (int z = 2 ; z < tempLength ; z++)
{
tempString = tempString + fileData [i].charAt (z);
}
xGridSize = Integer.parseInt (tempString);
System.out.println (" " + xGridSize);
blnXFound = true;
}
position = fileData [i].indexOf ("y=");
if (position >= 0)
{
tempLength = fileData [i].length (); // takes lenght so we know where the string ends
for (int z = 2 ; z < tempLength ; z++)
{
tempString = tempString + fileData [i].charAt (z); // adds the remaining digits together
}
yGridSize = Integer.parseInt (tempString);
System.out.println (" " + yGridSize);
blnYFound = true;
}
if (blnXFound == true && blnYFound == true)
{
break SearchGridSize;
}
}
}
}
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#12 |
|
Expert Programmer
|
Ah.
String temp = "";
BufferedReader in = new BufferedReader (new FileReader ("PieceData1.txt"));
while ((temp = in.readLine ()) != null)
{
fileCount = fileCount + 1;
}
in.close ();
System.out.print ("Size of file is: " + fileCount);
// size of file has been stored
// use the size of the file to make an array of the specified to size of the file
String fileData [] = new String [fileCount];
in = new BufferedReader (new FileReader ("PieceData1.txt"));
for (int i = 0 ; i < fileCount ; i++) //
{
fileData [i] = in.readLine ();
}
in.close ();Now that that's resolved, it seems you have a few other problems to deal with (ArrayIndexOutOfBounds exceptions). |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
marker = -1 ;
...
for ( int i = marker; ...
System.out.println ("position: " + fileData [i].indexOf ("<GPieceSize>"));
...Did you get everything worked out? |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
thanks for your help.
I'm at school right now so the codes not with me. I'll be back home in a few hours and i'll be able to get back to you on this.
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#15 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Yep thx.. I'm at home and it works now thanks. Now for the ArrayIndexOutOfBounds exceptions I did "int fileCount = 0" in the main method which created another variable (with the same name) which is different from the private data used in the class. That was an obvious mistake which I easily found on my own.
Thanks a lot for your help. Your advice helped a lot! Quote:
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|