Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Syntax error on token ";", { expected after this token please HELP

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Syntax error on token ";", { expected after this token please HELP

    import java.io.File;
     
    public class ModDetector{
     
     
     
    	public static class Detect{
    	File folder = new File("c:/");
    	File[] listOfFiles = folder.listFiles();
     
     
    	 for (int i = 0; i < listOfFiles.length; i++) {
    	      if (listOfFiles[i].isFile()) {
    	        System.out.println("File " + listOfFiles[i].getName());
    	      } else if (listOfFiles[i].isDirectory()) {
    	        System.out.println("Directory " + listOfFiles[i].getName());
    	      }
    	    }
    	  }
    	}
    }
    the problem is in 9th row, last token ";" plz help, quick fix no suggestions...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,576
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: Syntax error on token ";", { expected after this token please HELP

    Which line is the 9th line?
    You could have added a comment like: //<<<<<<<<<< LINE 9

    Better yet, post the full text of the compiler's error message.

  3. #3
    Member clydefrog's Avatar
    Join Date
    Feb 2012
    Posts
    67
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Default Re: Syntax error on token ";", { expected after this token please HELP

    i believe u have an extra '}'

    i dont know where but i count 5 '{' and 6 '}'

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Syntax error on token ";", { expected after this token please HELP

    You need to put your code within the main method. There is no application start point.

    public static void main(String args[]){
    // code to execute here
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Syntax error on token ";", { expected after this token please HELP

    I think this is what you intended:
    ...edited by moderator

    You have an extra closing curly brace at the end. Apart from that it seems to me that using a static inner class is probably not what you intend. If it is -- you must create a method inside the inner class which holds the code you want to run. You must then call that method from another part of your program (i.e. the main() method).
    Last edited by rektiphyr; March 1st, 2012 at 02:12 PM. Reason: Correcting SpoonFeeding

  6. #6
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Syntax error on token ";", { expected after this token please HELP

    @rektiphyr, please read the forum rules, as well as the following:
    The Problem with Spoon-feeding

  7. #7
    Junior Member
    Join Date
    Mar 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Syntax error on token ";", { expected after this token please HELP

    Quote Originally Posted by copeg View Post
    @rektiphyr, please read the forum rules, as well as the following:
    The Problem with Spoon-feeding
    My appologies -- I have now read and understand the forum rules. I have also edited my original post.

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  2. Replies: 2
    Last Post: September 23rd, 2011, 07:09 AM
  3. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  4. Why the error said "few parameters expected 7" while i only have 6 fields?
    By Hafiz Mughni in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2011, 10:45 AM
  5. Syntax error on token ";", @ expected after this token
    By MagicMojo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2011, 07:48 AM

Tags for this Thread