• Post Reply Bookmark Topic Watch Topic
  • New Topic

i need help  RSS feed

 
Ebunoluwa Adedoye
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
Was testing my ability on packages as in creating a package and importing the package.the compiler was giving me error on this code bellow:
package ebuno;
this where i declared my package
import javax.swing.*;
public class wole{

public int biola(){
System.out.println("i am a girl");
return(0);
}

}

this was where i imported it:
import ebuno;

import javax.swing.*;

public class mary{
public static void main(String args[]){
mary jnr=new mary();
jnr.biola;
System.exit(0);
}
}
the compiler is saying "expected '.' in import ebuno
dnt know what to do.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The argument to "import" is either the name of a class, or a wildcard ending in ".*" which stands in for all the classes in a package. You've imported just a bare package name, and that's not legal. You mean:

import ebuno.*;
 
megha ghanekar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
If u have more than one classes in a package. Add them to jar file. If you dont do so. wildcards wont work. You have to access the classes individually.

e.g:

package Pack1;

public class Demo1
{
}

public class Demo2
{


}

// in another file lets say i am importing all classee from Pack1 using *

import Pack1.*;
//it will import all the classes provided you have added them to a jar file.

or otherwise u have to explicitly import all the classs
import Pack1.Demo1;
import Pack1.Demo2;
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by megha ghanekar:
hi!
If u have more than one classes in a package. Add them to jar file. If you dont do so. wildcards wont work. You have to access the classes individually.

This is incorrect. You do NOT need a jar file to make wildcard imports work correctly. You only need to ensure that your .java files are in a directory hierarchy that matches your package names and that the CLASSPATH variable is set to the directory at the root of this hierarchy. Unfortunately, I don't have any links to help explain this more clearly. Perhaps there is something available in the Java Tutorial in my sig.

Layne
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this tutorial helps. Let me know if it's not clear.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!