aspose file tools*
The moose likes Beginning Java and the fly likes import java.io.*; problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import java.io.*; problem" Watch "import java.io.*; problem" New topic
Author

import java.io.*; problem

Rubens Martins
Greenhorn

Joined: May 02, 2010
Posts: 3
Hello everyone, I'm here cause I'm having this problem in my program:





what should I do about it? the tutorial I'm using does not say to save three different files, so I think this was supposed to work.

Ty


Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Your import statements need to be the first line in the saved file. So instead of having the import in the middle, move it to the top.

-Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Rubens Martins
Greenhorn

Joined: May 02, 2010
Posts: 3
As I said before, I am not supposed to save three different files. I've tried that already, and it states three errors:



and I have no idea of how to solve this.

Help please???

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Sorry I was a little confused at first since the title of this post was regarding imports. Now I think I know what you are asking. Only one class can be public within a java file. So remove the public keyword from all but one of the classes.

-Hunter
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14146
    
  18

Rubens Martins wrote:As I said before, I am not supposed to save three different files.

One of the rules of Java is that if you make a top-level class public, it has to be saved in a file with the same name as the class (and the .java extension). You have two public classes: SimpleDotCom and GameHelper. These need to be in two separate files named SimpleDotCom.java and GameHelper.java.

You can also make the classes not public, as Hunter suggests.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Rubens Martins wrote:

That error is unrelated to the classes being public or not. Math.random() is a method so you need to add parentheses.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Hunter McMillen wrote:Your import statements need to be the first line in the saved file. So instead of having the import in the middle, move it to the top.

-Hunter

It doesn't need to be the first line, but the only things that are allowed to be placed before import statements are the (optional) package declaration, comments and whitespace. Classes definitely do not fall into that group
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38792
    
  23
Yo have got answers, Rubens Martin, and welcome to the Ranch
Rubens Martins
Greenhorn

Joined: May 02, 2010
Posts: 3
Okay, I'll remove the publics and add parentheses, thanks everyone!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38792
    
  23
No, removing the public keywords is not the right answer. You ought to correct the names of the files.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import java.io.*; problem