• Post Reply Bookmark Topic Watch Topic
  • New Topic

Metthod within method need sloving  RSS feed

 
Teh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to correct the method within a method at line 267
please can someone slove it ?

 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you should do is to indent your code so the { symbols and the } symbols match up vertically. Then, since the error is caused because you don't have enough of one or the other kind of those symbols, it should be easier to find out where you missed one. If you are using an IDE like Netbeans or Eclipse then there's an option you can take to reformat your class.

As it is you have several hundred lines of code which is less readable than it should be. This problem is the consequence of having unreadable code.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You should also write code from outside in, rather from top to bottom, which reduces the risk of such mistakes.
 
Teh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive counted every { and } and they are equal but the thing is that i am nesting a method within a method and have no idea how to sort it out
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all in the main() method? Good grief! Any method that long ought to be divided into several methods.
Also that whole thing is non object-oriented; you ought to have classes for CPU, memory, etc.
 
Teh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only learnt this in like 4 weeks at colllege so im not the best :/
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Teh Singh wrote:Ive counted every { and } and they are equal...


Sure, but they are in the wrong order. I still suggest you format your code better. Even if you find your problem now, it will be easy for you to break it again and have the same problem.
 
Teh Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem is i aint learnt that far yet in college

and have half term but trying to finsih my program and have no idea how to have seperate classes for them etc.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why you don't write 300 lines of code before you compile. My guess is that you have something like this:



You'll notice I have the correct number of curly braces, but this code would be invalid. You have to close one method before you start the next. So my above example would be correctly written as this:
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Teh Singh wrote:Problem is i aint learnt that far yet in college

and have half term but trying to finsih my program and have no idea how to have seperate classes for them etc.


Your main method is from line 5 till 393, within this method you have another method printheader between line 267 and 276. That's causing the error. If you put the method outside of main and use it you can remove 87 lines of code from the main .

regards,
Ben
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about the semi-colon at the end of line 267, before the {?
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote:How about the semi-colon at the end of line 267, before the {?


Your totally right, I fixed that one and forgot to mention it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!