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

Thread: This Code worked on a separate class but does not work on another class

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default This Code worked on a separate class but does not work on another class

    this one is working on: public class Table {

    public int player() {
    Scanner in = new Scanner(System.in);
    p = in.nextInt();
    return p;
    }

    but does not work on another class but under main:

    public static void main (String[] args){

    Please help as this puzzles me as I am very new in JAVA ... thank you in advance


  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: This Code worked on a separate class but does not work on another class

    Please post the full text of the error messages and the full code that is causing them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: This Code worked on a separate class but does not work on another class

    Are you trying to copy the code from the method player() into method main()
    If so, here is the answer: methods having void type cannot return any values, the return statement needs to be replaced with something meaningful.

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: This Code worked on a separate class but does not work on another class

    @ ranjithfs1:
    I am trying to copy the whole method from another class to main. Even if I remove the return there is still error.
    "Multiple markers at this line
    - Syntax error on token(s), misplaced construct(s)
    - Syntax error on token "int", @ expected.

    @Norm: That is the whole code already.

  5. #5
    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: This Code worked on a separate class but does not work on another class

    Please post the full text of the error messages and the code that is in the source file. Copy it exactly as it is in the source file and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Do Class Casts Work With Arrays?
    By snowguy13 in forum Collections and Generics
    Replies: 8
    Last Post: February 23rd, 2012, 08:18 AM
  2. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM
  3. updating SWT Slider from separate java class
    By ppmckee in forum AWT / Java Swing
    Replies: 0
    Last Post: April 14th, 2011, 03:23 PM
  4. how to separate this code in another class
    By Jhovarie in forum AWT / Java Swing
    Replies: 2
    Last Post: February 28th, 2011, 06:22 PM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM