• Post Reply Bookmark Topic Watch Topic
  • New Topic

Are there errors in my code?  RSS feed

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So on this code I keep getting errors that are only just popping up and never have before.
So if any of you can copy this code and make sure there is no errors I would be so grateful.


 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are they compiler errors?

Look at the errors one by one, start with the first one and don't let yourself be overwhelmed if you get many errors at once. Carefully read the error message and try to understand what it's trying to tell you. The compiler also points exactly to the line of code where there's something wrong, so look at that place in the source code.

What's the first error message that you get? What do you think it means?

Your class also has an empty main method (line 15). If you solve all the compiler errors and run this class, it will do nothing at all, because the main method is empty.
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Are they compiler errors?

Look at the errors one by one, start with the first one and don't let yourself be overwhelmed if you get many errors at once. Carefully read the error message and try to understand what it's trying to tell you. The compiler also points exactly to the line of code where there's something wrong, so look at that place in the source code.

What's the first error message that you get? What do you think it means?

Your class also has an empty main method (line 15). If you solve all the compiler errors and run this class, it will do nothing at all, because the main method is empty.

Thats really nice and helpful info. Starting with the first error is i think is a compiler error. Where it says Welcome to pokemon it says 'Class' or 'interface' expected and these really confuse me.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you copy the full text of the error messages and paste it here?

It may be necessary for you to start over and reenter the source from the beginning.  You should compile the code after each unit has been entered. Fix the errors before going to the next unit.
For example enter the skeleton code for the class and compile.  Add some instance variables and compile.  Add a skeleton for a method and compile.  Add some code to the method and compile.
Always fix the compiler errors before adding more code.
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my comment on the other thread...you need to do a round of tidying up your indentation so you can see which brackets go with which.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:
Thats really nice and helpful info. Starting with the first error is i think is a compiler error. Where it says Welcome to pokemon it says 'Class' or 'interface' expected and these really confuse me.


Just compiled it. There are about 3 or 4 compile errors, but not where you specified. The errors are located in the playGame() method of your pokemon inner class, and the errors are related to using variables that doesn't exist (because they are out of scope mentioned here... https://coderanch.com/t/669156/java/java/#3124211).

Henry
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:So on this code I keep getting errors that are only just popping up and never have before.

This is the third thread on the same code that I've seen you post and you haven't fixed anything from the prior two. (like the empty main method I pointed out yesterday and the unintentional class-within-a-method):

https://coderanch.com/t/669247/java/java/Class-declarations-methods
https://coderanch.com/t/669245/java/java/Class-interface-expected-code

...and I'm not the first person to tell you about the main() method:
https://coderanch.com/t/669218/java/java/Errors-loops

I'm confused: do you want help learning to program in Java or do you want someone to write this for you one question at a time?

If the former, my advice to you is to take a free online Java tutorial so you understand the basics; otherwise, I can't really answer your questions since the answers require basic, foundational knowledge of the pieces-parts of Java, like what classes, objects, methods are and Java syntax.

 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julian West wrote:
This is the third thread on the same code that I've seen you post and you haven't fixed anything from the prior two.

Henry Wong wrote:
because they are out of scope mentioned here...


I was told to do Integer.parseInt for the variables which makes sense. So I did. And I had no problems with it everything compiled jut fine. Today I open up IntelliJ and well the variables are out of the scope. But why did they work for the past two days and all I have done in the past two days is delete the template at the top. (The /* ~~~~~~~~ */)
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget re-writing the code and everything I put at the top. The base of pretty much all my post was just to say really why errors pop up certain times and not other time.
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive figured it out i don't even know what it was. I had to un-inject some random stuff. I really don't know anyway its fixed!
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:Forget re-writing the code and everything I put at the top. The base of pretty much all my post was just to say really why errors pop up certain times and not other time.


There is no way that the code you posted will compile. Never. Not just sometimes. It should always fail to compile.

And ... even if you try to run it with the compile errors, which as already stated, you should never do, the posted code doesn't do anything -- as the main() method is empty.

Henry
 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bod McLeon wrote:Ive figured it out i don't even know what it was. I had to un-inject some random stuff. I really don't know anyway its fixed!


I just want to get a bit philosophical here.

A language allows you to communicate. A programming language is pretty much a communication between you and a computing device.
Imagine you posted a huge paragraph of poorly written text in french or hindi or arabic and you are asking whats wrong with this ? Why isn't the other person (java compiler) understanding me?
A sane answer would be, are you sure about the grammars in that language ?
You need to understand basics before you start writing essays
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was more of me being annoyed than actually not knowing what it was. I had injected a language reference to try and fix another error. And I just had to get rid of it. I also just had to move a curly brace/bracket so an integer/string was in the same scope.
 
Bod McLeon
Ranch Hand
Posts: 65
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Bod McLeon wrote:Forget re-writing the code and everything I put at the top. The base of pretty much all my post was just to say really why errors pop up certain times and not other time.


There is no way that the code you posted will compile. Never. Not just sometimes. It should always fail to compile.

And ... even if you try to run it with the compile errors, which as already stated, you should never do, the posted code doesn't do anything -- as the main() method is empty.

Henry


Im doing it at the moment. The boxes that pop up to help with the errors want me to turn it into something along the lines of 'private static void main()' which I know is not 'public static void main(String[] args)
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dropdown lists you get when you click the red mark on Eclipse are suggestions for corrections, not instructions. You usually get several possibilities, but you are free to ignore the suggestions and do something different.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!