• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import java.io.*; problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rubens Martins
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
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

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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yo have got answers, Rubens Martin, and welcome to the Ranch
 
Rubens Martins
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'll remove the publics and add parentheses, thanks everyone!
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, removing the public keywords is not the right answer. You ought to correct the names of the files.
 
reply
    Bookmark Topic Watch Topic
  • New Topic