Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Issue with cannot be applied to given type and cannot find symbol

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone'

I'm trying to do code here that creates the instance of a class to be used in the driver. But i'm having issues with cannot be applied to given type and cannot find symbol. Driver, and class files are below.

What do these errors actually mean and, how would I go about fixing them without using inheritance(extended reference)?






 
Saloon Keeper
Posts: 8447
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rectangle does not have a setLength() that takes two arguments. There are other problems with your code as well.

It would help if you would cut and paste the complete text of any error message into a post.
 
Emily Jason
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Removing the other variable type from calculation.setLength's parameters now has the program up and running from compiler.

The error messages were both "formal arguments not same length as actual arguments" Line 9, and "cannot find symbol" Line 12.
 
Carey Brown
Saloon Keeper
Posts: 8447
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one place you have lower case 'w' and the other you have upper case 'W'. Java is case sensitive.

The Java convention is that all variable and method names start with a lower case letter.
 
Marshal
Posts: 73738
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another mistake you are making, which will cause you no end of problems in future, is not formatting your code correctly. Look at our suggestions. Not indenting and not leaving spaces between successive methods will confuse you once you start needing >' 1 level of indentation, and will hide all sorts of potential errors from you. Another thing is that the long comments make the code difficult to read here, particularly for people who are reading on a screen only 3″ wide. Avoid comments like that on line 8 because they don't tell you anything that isn't obvious already.

Your comment on line 6 isn't quite accurate.
Don't go to all the trouble of choosing good names for your fields and then obscure them by using poor names for method parameters. Don't use w: use width. This is how it is done. Don't change the structuree of the method, or you can get different errors at runtime:-
 
Emily Jason
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, thanks for suggestions

I see the reason for "cannot find symbol" is because of the "W" instead of the "w" which was syntax err. This has been fixed. Editor used also doesn't have an auto-layout option but indenting methods by 3-4 spaces should work. I'll try to keep the comments shorter to 8 words so they don't expand on the line or above the method in a block if longer.  

Question about constructors. Normally, constructors can't be left without any methods inside or produces err if there are variables passed in its arguments. If a constructor is passed in another class, the arguements must be the same as in the original constructor or "formal paramaeters not same as arguments" occur?  
 
Sheriff
Posts: 16578
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Emily Jason wrote:I'll try to keep the comments shorter to 8 words so they don't expand on the line or above the method in a block if longer.



While you're learning, I guess it's ok to put comments in your code to remind you of what you were thinking when you were writing it. However, comments like this:

and this:

are actually worse than worthless. They are redundant and only create visual clutter in the code. Avoid comments that explain what and how. Good comments explain why something was done the way it was. Otherwise, let the code speak for itself by using self-documenting names, names that convey their intent well.  For example, instead of just w, use the full word that expresses what that variable represents, like width.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic