• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help with errors again

 
Greenhorn
Posts: 18
Netbeans IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Errors in code are as follows:
C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\src\week3mortcalcjp2\Week3mortcalcjp2.java:274: invalid method declaration; return type required
C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\src\week3mortcalcjp2\Week3mortcalcjp2.java:274: invalid method declaration; return type required
public setSize() {
1 error
C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.



 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\src\week3mortcalcjp2\Week3mortcalcjp2.java:274: invalid method declaration; return type required
C:\Users\LeeAnne\Documents\NetBeansProjects\week3mortcalcjp2\src\week3mortcalcjp2\Week3mortcalcjp2.java:274: invalid method declaration; return type required
public setSize() {
1 error



You must specify a return type for every method declaration, if the method is not supposed to return anything you must put void instead.
So
becomes
 
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Layman's term for "return type": what kind of thing does is this method supposed to return?

Your code:


doesn't say what kind of thing the setSize() method is supposed to return when you call it. So there's something missing right here:


Now it's quite possible the method isn't supposed to return anything. Maybe it's just supposed to do something and that's all. In which case there's a special value you are supposed to put in there. So let me suggest you check back in your text book, or whatever resource you are using to learn Java, and see if you can find what that special value might be.
 
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the code button, you get a pair of tags like this [code][/code]. Put the code after the first ].

Is that the only error you are suffering? The message is quite clear; you ought to give it a return type. Not public setSize() but public void setSize().
Don't write so much code and compile it. You should be compiling after every 5 lines or so. That will make it so much easier for you to find errors.
 
LeeAnne Murphy
Greenhorn
Posts: 18
Netbeans IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok changed that and now the lines below it are giving me errors.



Here is the error.

non-static variable frame cannot be referenced from a static context
 
Campbell Ritchie
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you got that static nested class in the first place?
 
LeeAnne Murphy
Greenhorn
Posts: 18
Netbeans IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm really sorry...I don't understand what you are asking.

Why have you got that static nested class in the first place? ( I don't understand static statements)
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the real cause of the error is getting obscured there. Looking at your original code, you've got a static class called setSize on line 268. Is that intended? It doesn't look right, and if it really is supposed to be a class it should start with a capital.

Then within that, you've got another class frame (again, should be Frame to follow standard conventions). Having an inner class inside an inner class is a bad idea even if it's possible (and I don't think it is). So maybe you need to rethink what that's supposed to be doing. Later on you try and treat frame like a variable rather than a class.

(I think. It's hard to read it accurately when your indentation is inconsistent).

Campbell's right - you need to try and keep your code simpler until you can get issues like this sorted out. Make sure you understand what each part of the code is supposed to be doing, rather than just trying to fix one error at a time.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you read this. The first line below the Static Nested Classes should answer your question why you are getting the error, but I'd study the whole article and familiarize yourself with the static keyword.
I also suspect you are a few steps ahead of yourself, which will only make things harder on you, good luck
 
Campbell Ritchie
Marshal
Posts: 79949
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have inadvertently created a nested (static) class inside your class. I suspect you don't want that class at all; maybe you clicked on the wrong box in NetBeans and it slipped that nested class in while you weren't watching.

That is another reason why we often recommend you avoid IDEs when you are starting.
 
Paul Clapham
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Having an inner class inside an inner class is a bad idea even if it's possible (and I don't think it is).



It is actually possible and I know that because I have done it. On purpose, too. But yeah... not really recommended. Especially for the beginner.

And as Campbell said, if you find that you did it accidentally then your code is a bit out of control. Or more likely a lot out of control.
 
We noticed he had no friends. So we gave him this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic