• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Problem = List of errors, Clueless. HELP

 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats my code guys.



And attached is the error thrown at compile time.


Please help me Guys!! I am frustrated as well belittled by my own class fellows
Untitled.jpg
[Thumbnail for Untitled.jpg]
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method main is missing an opening bracket {.
B.t.w. you could simplify your code by using the ++ operator.
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OUCH!!!
Thank you!
But I seem to have this frequent problem.
whenever I call anyother variable in Soprintln, it says can;t reference from non static context.
I have to declare the variable as static, is there anyway to override this problem.
Thanks again
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common problem for beginners. Because the main method is static you can't use non-static variables. You must created an instance and perform actions on that instance. However I would advise you to read some things about what static actually means. Because it is very basic and you must understand it in order to become a good programmer. It is not that difficult. Good luck
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wouter

Any good books you can refer, by good books, I really mean good books for a silly person like me! :P
Thanks again main...errr....man!!
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as a general note, you should never have gotten this error. Why? because you shouldn't have written this much code before compiling. Every time I write a program, I write exactly this before I compile it the first time



Once I compile this, I run it and make sure it does what I think it should, I write another line. and by that, I mean ONE line. Ok, I may declare a variable AND write a line, but not much more than that.

the idea is to write as little as possible before each compile/run/debug cycle. by doing this, you can be pretty sure where the error is. I use liberal System.out.println statements when writing my code too. I like to know exactly what it is doing at each and every step.

Writing 32 lines of code before compiling it scare the heck out of me...I would STRONGLY advise you not to do it. If you had done this, you would have pretty quickly found your missing brace, rather than getting this massive list of errors which are all caused by one missing character.
 
Shashank Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well said FRED!
Thanks for that great TIP. I will take care of it next time. Really!
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't help you with finding a good book because I learned it almost entirely from the internet. I'd advise you to read sun's java tutorial. It's not the easiest one out there but it's good.
One thing I can't stress enough. Write code, write code, write code, WRITE CODE! Because only then will you learn. If you only read about it then you will never get it. And remember
you can't learn good programming within a day, week, month. It takes lots and lots of practice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic