• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with my "while loop" code  RSS feed

 
Timothy Han
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I don't know what is wrong with my code.  I'm learning how to do a while loop in NetBeans, and this is the error I got for my code: "Error: Could not find or load main class do_while.loops.Do_WhileLoops
C:\Users\Timothy\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)"


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. That code looks fine.

While not illegal, it is uncommon to have an underscore in a package name. Can you try removing the underscore and seeing if it changes anything?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package must come first.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CB is right: the package declaration must come before the import declaration. I am surprised you didn't get an error when you tried to compile that file. It shows how using an IDE at too early a stage in one's career can cause confusion.
My javac tool wrote:javac -d . Do_WhileLoop.java
Do_WhileLoop.java:3: error: class, interface, or enum expected
package do_while.loops;
^
1 error
I tried it with Eclipse and got different error messages.

Thank you for using the code tags, but don't double‑space code like that. It is easier to read with most of the code as a block, like this:-Another formatting thing: you shou‍ld leave a space before the { Look at lines 5, 7 and 15 in your version. You can probably get NetBeans to correct the formatting with a few keystrokes. The name of your class is misleading; you don't have a do‑while loop in your code at all.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also argue that this is exactly why you should compile more often. If you wrote all that code and only then compiled it for the first time, it can be VERY hard to find the problem.  However, if you had just written this much before your first compile:


Now you have a lot fewer places to look for a problem.  Once you fix that problem (and test the code), you can add one or two lines, and compile/test again.  If all is well, add a few more lines.  If there is a new error, you know it has to be in the 1-2 lines you just added.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!