Results 1 to 9 of 9
  1. #1
    flpanthers1 is offline Member
    Join Date
    May 2011
    Posts
    8
    Rep Power
    0

    Default Issue with "void type not allowed here" and I cannot see why.

    So I started my first Java class last week, and Ia m having problems. The question I have in my assignment is;

    "Create an application named TestMethods whose main() methods holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayIt(), displayItTimesTwo(), and displatItPlusOneHundred(). Create each method to perform the task its name implies. Save the application as TestMethods.java."

    So this is what I have so far...


    Java Code:
    public class TestMethods
    {
      public static void main(String[] args)
      {
           int myVariable1 = 10;
           int myVariable2 = 27;
           System.out.println(displayIt (myVariable1, myVariable2));
      }
    
      public static void displayIt(int myVariable1, int myVariable2)
      {
           System.out.println("My two variables are " + myVariable1 + " and " + myVariable2);
      }
    }

    I keep getting "void type not allowed here" on line 16 which is bold. What am I doing wrong here? This is my first assignment, and it has been frustrating. I know it's an easy question, but I cannot get it in to code for the very first part. Any help is greatly appreciated.
    Last edited by DarrylBurke; 05-25-2011 at 05:38 PM. Reason: Added code tags, removed blank lines in code

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default

    See answer on the other forum where you posted this question.
    1st Java class assignment, and having some difficulties. Little help please.
    Last edited by Norm; 05-25-2011 at 05:44 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    You're asking System.out to println the value returned by displayIt(...). Problem is, that method doesn't return a value.

    db

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Also I think this:
    "In turn, pass each value to methods named displayIt(), displayItTimesTwo(), and displatItPlusOneHundred()."
    means that the methods take one integer and does what the method says with it. You then call this method once for the first integer then again for the second one.
    It doesn't imply to me that you send in both integers at the same time, otherwise they'd be called displayThem...etc.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    Also I think this:
    "In turn, pass each value to methods named displayIt(), displayItTimesTwo(), and displatItPlusOneHundred()."
    means that the methods take one integer and does what the method says with it. You then call this method once for the first integer then again for the second one.
    It doesn't imply to me that you send in both integers at the same time, otherwise they'd be called displayThem...etc.
    Nitpicker, if I want to name my methods foo1, foo2 etc. I'm free to do so; this is a free country.

    kind regards,

    Loretta (<-- that's my name ;-)
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default

    Not everyone lives in Holland.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Which is probably a good thing as it would get a little crowded...
    Imagine the property prices!

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Not everyone lives in Holland.
    Normally I name my methods f, g, h etc. to conserve space; I also use as few new lines as possible. I am CO2 neutral ;-)

    k. r.

    J.
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

Similar Threads

  1. void type not allowed
    By jockhip12 in forum New To Java
    Replies: 6
    Last Post: 05-05-2011, 05:26 PM
  2. Equivalent of " void* " in JAVA
    By ABHIJEEEEEEET in forum New To Java
    Replies: 7
    Last Post: 08-16-2010, 06:55 AM
  3. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 08:54 PM
  4. Replies: 3
    Last Post: 05-21-2009, 03:48 PM
  5. 'void' type not allowed here
    By Torgero in forum New To Java
    Replies: 15
    Last Post: 10-04-2008, 11:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •