Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-10-2008, 10:58 PM
Member
 
Join Date: Jan 2008
Posts: 4
inksmithy is on a distinguished road
<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.

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.

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

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

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-10-2008, 11:44 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
This error is occurring because you are trying to pass nothing to a method that requires a String.

Code:
this.inputSize() = startSize;
inputSize requires a String in its parameters. In this line, you have called inputSize with no parameters.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-11-2008, 12:13 AM
Member
 
Join Date: Jan 2008
Posts: 4
inksmithy is on a distinguished road
So if I rewrite
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
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 01:21 AM. Reason: add a code tag
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-11-2008, 02:13 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
I'm glad i could help inksmithy =]
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-13-2008, 03:44 PM
Member
 
Join Date: Jan 2008
Posts: 4
inksmithy is on a distinguished road
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:

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

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:

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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-14-2008, 12:36 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Good job man. I'm glad i could help you out.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 2 09-18-2008 09:30 AM
Error: cannot be applied to (java.lang.String) carl New To Java 1 08-05-2007 08:33 AM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 12:52 PM
Cast Error Caught (change) Class is really: java.lang.String barney Advanced Java 1 08-02-2007 06:07 PM
Can't convert java.lang.String to int. Albert AWT / Swing 2 07-13-2007 07:05 PM


All times are GMT +3. The time now is 02:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org