• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Illegal Start of Expression

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Lucas Laws
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked for missing braces already, and everything lines up perfectly.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic