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

Thread: What Is Wrong With This Code

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default What Is Wrong With This Code

    I am trying to create a multiple class program and its coming up with errors this is the code

    First Class Named Test1

    This Class is coming up with errors Its Saying "Syntax error on token "message", VariableDeclarator expected after this token"
    import java.util.Scanner;
     
     
    public class Test1 {
    	public static void main(String[] args){
    		System.out.println("Welcome User My Name Is JARVIS ");
    		Scanner input = new Scanner(System.in);
    		// This Is The Input Command Line 
    		System.out.print("Enter Username: ");
    		// This Is Where Users Enter Their Username
    		String line = input.nextLine();
    		// This Command Puts The Entered Username onto the next line
    		System.out.println("Welcome User " + line);
    		// This Combines The Welcome User With The Inputed Text:)
    	}
     
    	Test2 Test2Object = new Test2();
    	Test2Object.message;

    Second Class Named Test2
     
    public class Test2 {
    	public void message(){
    		System.out.println("This is Test2 Class");
    	}
    }
    Please Help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What Is Wrong With This Code

    its coming up with errors
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Camwarp (November 7th, 2013)

  4. #3
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: What Is Wrong With This Code

    The way you called message is as if it were a field. To call a method you must have parenthesis after the method call
    Test2Object.message();

  5. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: What Is Wrong With This Code

    Thanks

    --- Update ---

    Still Not Working Tried Adding The Parentheses Didnt Remove The Error

    This Is The New Code
    Error Is As Follows "Syntax error on token "simpleMessage", Identifier expected after this token"
    import java.util.Scanner;
     
     
    public class Test1 {
    	public static void main(String[] args){
    		System.out.println("Welcome User My Name Is JARVIS ");
    		Scanner input = new Scanner(System.in);
    		// This Is The Input Command Line 
    		System.out.print("Enter Username: ");
    		// This Is Where Users Enter Their Username
    		String line = input.nextLine();
    		// This Command Puts The Entered Username onto the next line
    		System.out.println("Welcome User " + line);
    		// This Combines The Welcome User With The Inputed Text:)
    	}
     
    	Test2 Test2Object = new Test2();
    	Test2Object.simpleMessage();
     
     
    }

  6. #5
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: What Is Wrong With This Code

    Oh...I don't see how I missed it before.
    You can't run code outside of a method. Move that bit of code into your main method

  7. The Following User Says Thank You to Parranoia For This Useful Post:

    Camwarp (November 7th, 2013)

  8. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: What Is Wrong With This Code

    THANKS

Similar Threads

  1. what is wrong with my code
    By BLUEJ in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 10th, 2013, 07:52 PM
  2. what is wrong with my code? need help
    By balmung123 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 1st, 2012, 04:12 AM
  3. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 28th, 2012, 09:08 PM
  4. need help .. what is wrong with my code.
    By baig-sh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 10th, 2011, 07:28 PM
  5. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM