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 10 of 10

Thread: Sytax Error "Delete this Token"

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sytax Error "Delete this Token"

    I'm having difficulty executing the "LastName" portion of the code. I'm trying to have it so the program will respond with the Name of the student. Unfortunately, the IDE (Eclipse) has stated that "lastName" is a lost token, and that the token "lastName" should be deleted. I'm not sure why it accepts firstName, but lastName causes an issue. Any help would be greatly appreciated.

    import java.util.Scanner;										
     
    public class Student {
     
    	private String studentName;
    	private Grades studentGrades = new Grades();
     
     
    	public void setup(){
    		setStudentName();
    		setStudentGrades();
    	}
    	private void setStudentName(){
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("\nProvide Your Name in the Following Order: Lastname, Firstname");
     
    		studentName = keyboard.nextLine();
     
    		studentName = studentName.trim();
     
    		int between = studentName.indexOf(",");
     
    		String lastName = studentName.substring(0, between);
     
    		String firstName = studentName.substring(between+2, studentName.length());
     
    		studentName = firstName + " " lastName;
    	}
     
    	private void setStudentGrades(){
    		studentGrades.setup();
    	}
     
    	public void display(){
    		System.out.println("\n Your Name is the Following: " + studentName);
    		studentGrades.display();
    	}
     
    	public double overallGrade(){
    		return studentGrades.average();
    	}
     
    }


    Sorry if the post is unorganized, this is my first time posting here, and I'm not sure how to have the code recognized as Java code here.
    Last edited by Grendarab; September 24th, 2014 at 08:48 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sytax Error "Delete this Token"

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    It's hard to say what the problem is without seeing the whole of the code. Too many definitions are missing from the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sytax Error "Delete this Token"

    Thank You! I edited the code into the proper format. I also added the rest of the code for that particular class, albeit I'm not sure if it's sufficient to solve the issue at hand. There are two more classes that I'm currently using, should I add those as well?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sytax Error "Delete this Token"

    Can you copy the full text of the error message and paste it here? Something that shows what you are talking about.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sytax Error "Delete this Token"

    This is what occurs when I attempt to execute the program.

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    Syntax error on token "lastName", delete this token
     
    	at Student.setStudentName(Student.java:35)
    	at Student.setup(Student.java:17)
    	at Main.main(Main.java:13)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sytax Error "Delete this Token"

    The error message left out the text of the statement and the place in the statement where the problem is.

    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sytax Error "Delete this Token"

    Sorry, I'm not too entirely sure where I can find that particular error statement within the compiler I'm using (Eclipse). Does this help?

    Description	Resource	Path	Location	Type
    Syntax error on token "lastName", delete this token	Student.java	/Project1/src	line 35	Java Problem

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sytax Error "Delete this Token"

    No help. What is the source line with the error?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sytax Error "Delete this Token"

    I was able to eliminate the error, but when executing the program, I obtain the following "JohnAdams", instead of "John Adams". This is what I changed

    studentName = firstName + lastName;

    How can I change it so the output will result with a space in between?

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Sytax Error "Delete this Token"

    So the error was at this line (you could have said several posts ago):

    studentName = firstName + " " lastName;

    You 'fixed' it by removing the " " (now causing your wrong output), but you could have fixed both problems by adding another '+'.

Similar Threads

  1. Replies: 2
    Last Post: May 22nd, 2014, 01:17 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. [SOLVED] Syntax error on token "extends", throws expected
    By Purple01 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 16th, 2012, 07:29 AM
  4. Syntax error on token ";", { expected after this token please HELP
    By Creeper in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 1st, 2012, 03:12 PM
  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