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

Importing Files

Amri Harimi
Greenhorn

Joined: Dec 29, 2003
Posts: 3
I get the following error when compiling my program:
CClientUIApp.java:14 '.' expected
import JavaBayes;

This did not used to happen when I would compile on my 98 machine. Could it be some setting somewhere that Im not aware of?
Thanks,
Amri
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You can't import classes from the default package; the compiler won't allow it. Whether it's legal in the language has been debated, but obviously the official compiler is a de-facto language standard. Older compilers did, in fact, allow this.
So don't put classes in the default package. If you're writing a class to be used by other classes, be sure to put it into a named package.


[Jess in Action][AskingGoodQuestions]
Amri Harimi
Greenhorn

Joined: Dec 29, 2003
Posts: 3
Thanks Ernest.
Im not sure how to put this class into a named package. Can you/someone please tell me how to do this?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

If CClientUIApp isn't already in a named package, then it doesn't need to import "JavaBayes" to use it, so deleting the offending line may help in this case.
But basically, you put a package statement at the top of the .java file
package mypackage;
Then make a directory mypackage and move the .java file into mypackage; then compile using
javac mypackage\JavaBayes.java
Then use
import mypackage.JavaBayes;
to refer to this class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importing Files