aspose file tools*
The moose likes Beginning Java and the fly likes New DotComClass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New DotComClass" Watch "New DotComClass" New topic
Author

New DotComClass

Spandan Pandey
Greenhorn

Joined: Feb 20, 2013
Posts: 10
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:
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Feb 20, 2013
Posts: 10
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New DotComClass