Results 1 to 6 of 6
- 01-10-2008, 08:58 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
<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.
is the constructor I am attempting to create.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(); }
andJava 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."); } }
are the two methods I am trying to call when the class is initialised.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'."); } }
The idea is (in the modified BlueJ workspace) when
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.Java Code:Triangle t; t = new Triangle();
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
I don't know what I've done wrong here, can anyone please pont me in the right direction?Java Code:inputSize(java.lang.String) in Triangle cannot be applied to ()
cheers,
Alan
- 01-10-2008, 09:44 PM #2
This error is occurring because you are trying to pass nothing to a method that requires a String.
inputSize requires a String in its parameters. In this line, you have called inputSize with no parameters.Java Code:this.inputSize() = startSize;
- 01-10-2008, 10:13 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
So if I rewrite
to readJava 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."); } }The method should work?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."); } }
/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-10-2008 at 11:21 PM. Reason: add a code tag
- 01-11-2008, 12:13 AM #4
I'm glad i could help inksmithy =]
- 01-13-2008, 01:44 PM #5
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
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:
andJava 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(); } }
Which allowed me to create the constructor as follows: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 does exactly what the question asks for and makes me feel just a little bit happy about getting it right.Java Code:public Triangle() { super(); // M255 TMA 02 Q1 (i) size = 5; orientation = "down"; // M255 TMA 02 Q1 (vii) this.inputSize(); this.inputOrientation(); }
Once again, thanks for your help gibsonrocker800.
cheers,
Alan
- 01-13-2008, 10:36 PM #6
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Error: cannot be applied to (java.lang.String)
By carl in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:33 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM -
Cast Error Caught (change) Class is really: java.lang.String
By barney in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 04:07 PM -
Can't convert java.lang.String to int.
By Albert in forum AWT / SwingReplies: 2Last Post: 07-13-2007, 05:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks