• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing Files

 
Amri Harimi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amri Harimi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic