wood burning stoves*
The moose likes Beginning Java and the fly likes Help with errors again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with errors again" Watch "Help with errors again" New topic
Author

Help with errors again

LeeAnne Murphy
Greenhorn

Joined: Aug 15, 2011
Posts: 18

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.



Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39882
    
  28
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

Joined: Aug 15, 2011
Posts: 18

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
Sheriff

Joined: Oct 13, 2005
Posts: 39882
    
  28
Why have you got that static nested class in the first place?
LeeAnne Murphy
Greenhorn

Joined: Aug 15, 2011
Posts: 18

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)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4467
    
    8

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

Joined: Apr 30, 2005
Posts: 164
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
Sheriff

Joined: Oct 13, 2005
Posts: 39882
    
  28
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
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with errors again