Forums Register Login

i need help

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.*;
+Pie Number of slices to send: Send
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;
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
See if this tutorial helps. Let me know if it's not clear.
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1056 times.
Similar Threads
need help to understand packages
information regarding the import...
Error Help
Note able to run java program, urgent!!
Music transcription program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:05:27.