• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implicit Import is not working - import planets.*; not working.........  RSS feed

 
Avi Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to JAVA Coding (1 week).....but i have learned several languages before (c,c++,php.....etc)....anyhow i am having problem with importing using asterisk (*).......I will try to explain in the best way I can.........any help would be great.......thank you in advance.......

Objective:

Create a main file find.java and create 3 other class files earth.java, mars.java. pluto.java. Run find.java and display the System.out.println from the all the files....

File Locations:

find.java - C:/JAVA Codes/planets
find.class - C:/JAVA Codes/planets
earth.java, mars.java, pluto.java - C:/JAVA Codes/planets
earth.class, mars.class, pluto.class - C:/JAVA Codes/planets/planets1

So, the .class files are in folder called planet1. The .java files are in the same location that is planet. What I am trying to do is run find.class and import all other classes from planets1

Error:

When using - import planets1.*; I am getting cannot locate earth class. However, when I use import planets1.earth; import planets1.mars; import planets1.pluto; The code works perfectly

Any suggestions ???




find.java





earth.java




mars.java




pluto.java




 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Avi and welcome to the Ranch!

Avi Singh wrote:When using - import planets1.*; I am getting cannot locate earth class. However, when I use import planets1.earth; import planets1.mars; import planets1.pluto; The code works perfectly

When seeking help with an error, it always helps if you copy and paste the exact error text. There isn't a Java compiler or runtime error that would report
cannot locate earth class

Have you learned about constructors? They don't have a return type, not even void.

Edit: Sorry, that wasn't clear. What I meant was that it's bad form to have a method with the same name as a class.

Additionally, by convention Java class names start with an uppercase letter.
 
Avi Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Darryl Burke

Thanks for the tips......i will keep it in mind during my next codes..........


Here is the exact error......



find.java:14: error: cannot access earth
earth e1 = new earth();
^
bad source file: .\earth.java
file does not contain class earth
Please remove or make sure it appears in the correct subdirectory of the sou
rcepath.
1 error

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!