Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing classes  RSS feed

 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an html with an applet. I have two java classes School.java and Alert.java

They are in the same folder and I have tried in Alert.java Import School.java; though it does not like this. Any ideas?

Thanks,
Randy
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did your compile tell you that it did not like it?
[ June 22, 2006: Message edited by: Edwin Dalorzo ]
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it thinks that it is some sort of package. Even though it is just the class itself. Should i just put both into a package? If so how do i do this?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the exact command you're using to compile, as well as the exact (and full) error message? believe it or not, it's chock full of information on why things don't work how you think they should.
 
Campbell Ritchie
Marshal
Posts: 55722
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randy, thank you.

But you have explained yourself why it doesn't work. Check the syntax and spelling for an import statement, and check which folders you have to import from.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. If you have two classes in the same package (and the same directory), then you do not need to import the other class at all. So just remove the import statement.

2. The import statement is not a kind of C/C++ #include statement. It does not read in source code of another file. So a statement like:

import School.java;

is not a correct import statement. This does not import School.java the way you think - it looks for a class named "java" in a package named "School".
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot import from the default package - this is why all declarations should include a package statement. The key point is that you need to clue up on packages and how they are used.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!