Results 1 to 6 of 6
  1. #1
    inksmithy is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default <variable>(Java.lang.string) in <classname> cannot be applies to ()

    Ok, now I realise this is only my second post and I'm sorry that its going to be a biggie, but this has me completely stumped.

    To start with, this is for a university course, so I don't want you guys to give me the answer (IE code) but I would love some idea of where it is I am going wrong here. I'll post the code.

    Java Code:
    public class Triangle
    {
       /* instance variables */
       int size; // the size of the triangle; an integer between 2 and 10 inclusive
       String orientation; // either "up" or "down"
       String startSize;
       String startOrientation;
    
       /**
        * Constructor for objects of class Triangle. 
        */
       public Triangle()
       {
          // super();
    //       M255 TMA 02 Q1 (i)
    //          size = 5;
    //          orientation = "down";
             this.inputSize() = startSize;
             this.inputOrientation() = startOrientation();
          
       }
    is the constructor I am attempting to create.

    Java Code:
    public void inputSize(String uSize)
         {
            uSize = OUDialog.request("Please enter an integer between 2 and 10 inclusive.");
            if (this.isValidSize(uSize))
            {
                size = Integer.parseInt(uSize);
             }
            else
            {
                OUDialog.alert(uSize + " is outside the parameters of the request.");
             }
             
          }
    and

    Java Code:
    public void inputOrientation(String uOrientation)
          {
             uOrientation = OUDialog.request("Please enter the orientation of your triangle, 'up' or 'down'.");
             if (this.isValidOrientation(uOrientation))
                {
                   orientation = uOrientation;
                }
             else
                {
                   OUDialog.alert(uOrientation + " is neither the word 'up' or 'down'.");
                }
             }
    are the two methods I am trying to call when the class is initialised.

    The idea is (in the modified BlueJ workspace) when
    Java Code:
    Triangle t;
    t = new Triangle();
    is executed, a dialog box comes up asking for the size and orientation of the desired triangle. If neither of them fall within the requested parameters, the user is alerted and told to try again.

    I'm happy with the two loops inputSize() and inputOrientation() but when I try to compile with the new constructor (posted waaay above) I get an error which says

    Java Code:
    inputSize(java.lang.String) in Triangle cannot be applied to ()
    I don't know what I've done wrong here, can anyone please pont me in the right direction?

    cheers,

    Alan

  2. #2
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    This error is occurring because you are trying to pass nothing to a method that requires a String.

    Java Code:
    this.inputSize() = startSize;
    inputSize requires a String in its parameters. In this line, you have called inputSize with no parameters.

  3. #3
    inksmithy is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default

    So if I rewrite
    Java Code:
    public void inputSize(String uSize)
         {
            uSize = OUDialog.request("Please enter an integer between 2 and 10 inclusive.");
            if (this.isValidSize(uSize))
            {
                size = Integer.parseInt(uSize);
             }
            else
            {
                OUDialog.alert(uSize + " is outside the parameters of the request.");
             }
             
          }
    to read
    Java Code:
    public String inputSize()
         {
            String uSize = OUDialog.request("Please enter an integer between 2 and 10 inclusive.");
            if (this.isValidSize(uSize))
            {
                size = Integer.parseInt(uSize);
             }
            else
            {
                OUDialog.alert(uSize + " is outside the parameters of the request.");
             }
             
          }
    The method should work?

    /update/ I just edited these to reflect the way I interpreted that ad came up with an error [code]Cannot find symbol - method startOrientation.

    /update again - I just proofread this and fixed the variable/method switch I made (duh), now I'm coming up with found void but expected string errors. I'm going to have to do more work on this tomorrow I think.

    By the way gibsonRocker800, thanks very much for your answer, you pointed me down the right track.
    Last edited by inksmithy; 01-11-2008 at 12:21 AM. Reason: add a code tag

  4. #4
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    I'm glad i could help inksmithy =]

  5. #5
    inksmithy is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default

    Just an update to this post showing how I fixed the problem thanks to gibsonrocker800s help.

    He gave me the hint that I was passing nothing to a method which wanted a string passed to it, so I gave it a good dose of looking at and came up wth this:

    Java Code:
    public void inputSize()
         {
            String uSize = OUDialog.request("Please enter an integer between 2 and 10 inclusive.");
            if (this.isValidSize(uSize))
            {
                size = Integer.parseInt(uSize);
             }
             else
             {
                OUDialog.alert(uSize + " is outside the parameters of the request." + 
                                              " Please enter a number between 2 and 10");
                this.inputSize();
              }
             
          }
    and

    Java Code:
    public void inputOrientation()
          {
             String uOrientation = OUDialog.request("Please enter the orientation of your triangle, 'up' or 'down'.");
             if (this.isValidOrientation(uOrientation))
                {
                   orientation = uOrientation;
                }
             else
                {
                   OUDialog.alert(uOrientation + " is neither the word 'up' or 'down'.");
                   this.inputOrientation();
                   
                }
                
             }
    Which allowed me to create the constructor as follows:

    Java Code:
    public Triangle()
       {
           super();
    //       M255 TMA 02 Q1 (i)
           size = 5;
           orientation = "down";
           
           // M255 TMA 02 Q1 (vii)
           this.inputSize();
           this.inputOrientation();
          
       }
    Which does exactly what the question asks for and makes me feel just a little bit happy about getting it right.

    Once again, thanks for your help gibsonrocker800.

    cheers,

    Alan

  6. #6
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  2. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 07:33 AM
  3. Replies: 1
    Last Post: 08-03-2007, 11:52 AM
  4. Replies: 1
    Last Post: 08-02-2007, 05:07 PM
  5. Can't convert java.lang.String to int.
    By Albert in forum AWT / Swing
    Replies: 2
    Last Post: 07-13-2007, 06:05 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
  •