Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

New DotComClass

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the new and improve DotComClass an error is coming at the command prompt like this.Can you please tell me how to get rid of that error.
Error:
SimpleDotCom.java:18:class,interface or enum expected
import java.util.ArrayList;
^
1 Error

My Code:
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the imports in a .java file have to go at the top of that file. The only thing that can come before them is the package statement and comments.

This is why the error message says, "class,interface or enum expected." Those are the only things that can appear where you've put that import statement.

Pay close attention to the error messages, they usually tell you exactly what's wrong, even if it's not immediately obvious at first glance what they're saying.
 
Spandan Pandey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:All the imports in a .java file have to go at the top of that file. The only thing that can come before them is the package statement and comments.

This is why the error message says, "class,interface or enum expected." Those are the only things that can appear where you've put that import statement.

Pay close attention to the error messages, they usually tell you exactly what's wrong, even if it's not immediately obvious at first glance what they're saying.


I understood you and did that.I did some corrections and the .java file compiled without any error but the error began in the output
Here is my code..Is My conversion of the int random numbers into string and using in checkyourself method is wrong?If not then why the output error..the program gets stuck asking-enter the number perpetually.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally, you put classes in separate source files. So, instead of putting this all in one source file, you should create three separate files, named GameHelper.java, DotCom.java and SimpleDotComGame.java, that contain these three classes respectively.

Note that for public classes (your classes are not public), it's required to have them in a source file that has the same name as the class name; you cannot have more than one public class per source file.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic