wood burning stoves*
The moose likes Beginning Java and the fly likes Illegal Start of Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Illegal Start of Expression" Watch "Illegal Start of Expression" New topic
Author

Illegal Start of Expression

Lucas Laws
Greenhorn

Joined: Sep 13, 2006
Posts: 16
So, this is probably just something really minor that I'm missing, but I've racked my brain debugging this for awhile and havn't found a fix, so maybe you guys can help me out.

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

public class VectorDemo
{
public static void main(String[] args)
{

int arrayCount = 0;
int charValue = 0;

PrintWriter fileOutput = null;//create the PrintWriter object before the try{ so it will not die at the } ending the try

try
{
BufferedReader inputStreamCounter = new BufferedReader(new FileReader("PetRecords.txt"));
String line = inputStreamCounter.readLine();

while(line != null)//count the total number of lines being read from the file
{
arrayCount++;
line = inputStreamCounter.readLine();
}

inputStreamCounter.close();//close the stream so it can be reopened to write to the vector

BufferedReader inputStream = new BufferedReader(new FileReader("PetRecords.txt"));

Vector<String> petVector = new Vector<String>(10);

for(int x = 0; x < arrayCount - 1; x++)//gather data from file into the vector
{
petVector.addElement(inputStream.readLine());
}

for(int x = 0; x < arrayCount - 1; x++)
{
if(petVector.elementAt(x) == " ") //removes all whitespace lines from the vector
{ petVector.removeElementAt(x); }//makes name be at index 0 + 3n, age at 1 + 3n, and weight at 2 + 3n
}

public static void sort(int charValue)//create method to check value of letters in name to alphabetize.
{//recurve if name(0) == name2(0)

for(int x = 0; x < petVecor.size() - 2; x += 3)
{
if(petVector.elementAt(x).charAt(charValue) > petVector.elementAt(x + 3).charAt(charValue))
{
String vectorTempOne = petVector.elementAt(x);//copies the pet record from x to temporary variables
String vectorTempTwo = petVector.elementAt(x + 1);//to transfer x+3 to x, and x to x+3
String vectorTempThree = petVector.elementAt(x + 2);

petVector.setElementAt(petVector.elementAt(x + 3), x);//copying the record starting at x+3 to x
petVector.setElementAt(petVector.elementAt(x + 4), x + 1);
petVector.setElementAt(petVector.elementAt(x + 5), x + 2);

petVector.setElementAt(vectorTempOne, x + 3);//copying the record that was put in temp vars to x+3
petVector.setElementAt(vectorTempTwo, x + 4);
petVector.setElementAt(vectorTempThree, x + 5);
}

if(petVector.elementAt(x).charAt(charValue) == petVector.elementAt(x + 3).charAt(charValue))
{
charValue++;
VectorDemo.sort(charValue);
}
}
}

VectorDemo.sort(0);

fileOutput = new PrintWriter(new FileOutputStream("PetRecordOutput.txt"));

for(int x = 0; x < petRecord.size() - 2; x += 3)
{
fileOutput.println(petRecord.elementAt(x) + "\n" + petRecord.elementAt(x + 1) + "\n" + petRecord.elementAt(x + 2));
}
fileOutput.close(); //close the file stream when done
}

catch(FileNotFoundException e)
{
System.out.println("File PetRecords.txt not found.");
}

catch(IOException e)
{
System.out.println("Problem reading from file.");
}

}
}


Basically I'm reading in a "Pet Record" from a file, which is just a name on one line, age on next line, and weight on the line after that. I then need to sort all the record by name alphabetically, and output it to a file. I can't debug the rest of it until I get this error fixed.

I'm getting an illegal start of expression on line 42 (which is my sort method).
[ October 30, 2006: Message edited by: Lucas Laws ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

I'm getting an illegal start of expression on line 42 (which is my sort method).


Generally, an "illegal start of expression" is caused by missing braces from the previous method. I suggest checking that first.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Lucas Laws
Greenhorn

Joined: Sep 13, 2006
Posts: 16
I have checked for missing braces already, and everything lines up perfectly.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Originally posted by Lucas Laws:
I have checked for missing braces already, and everything lines up perfectly.


Check it again. You are missing two close braces in the main() method. (not to mention a "catch" and/or "finally" for the "try")


Upon further examination, it looks like those missing braces are after the sort() method -- basically you placed the sort method inside the main() method, which is not allowed.

Henry
[ October 30, 2006: Message edited by: Henry Wong ]
Lucas Laws
Greenhorn

Joined: Sep 13, 2006
Posts: 16
Ok, I'll move it out of main and try to work everything into a happy order then. Thanks.
[ October 30, 2006: Message edited by: Lucas Laws ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal Start of Expression
 
Similar Threads
Vectors passed to a static method?
Entering many records..Need help!
Writing to a file...Please help...
Problems reading from a .txt file
Input files???