• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

importing multiple classes from a package

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm using d:\corejava as a current and running folder, where i had set path as "d:\corejava>set path=c:\java\jdk1.6.0_24\bin;".
I created two helper java files i,e D:\corejava\A.java and D:\corejava\B.java and executable java file as "D:\corejava\TestPackage3.java"







I compiled A.java and B.java as "javac -d . A.java" and "javac -d . B.java" Upto here it is good.

Step 1:-

I try to set classpath as "D:\corejava>set classpath=D:\corejava;.;" then I compiled TestPackage3.java as "javac TestPackage3.java" here i got error as


TestPackage3.java:6: cannot access A
bad class file: .\A.java
file does not contain class A
Please remove or make sure it appears in the correct subdirectory of the classpath.
A a = new A();
^
1 error



Step 2:-

Again I try to set classpath as "D:\corejava>set classpath=D:\corejava\com;.;" then I compiled TestPackage3.java as "javac TestPackage3.java" again I got the same error as above

Step 3:-

Again I changed "import com.*" to "import com.A; import com.B" then it is working fine.

Now I want to know is there is any errors in executable file or in helper file or in classpath setting. Anticipating a positive reply.


 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your folder structure needs to match the package structure. So, for instance, if A is in package com, it needs to be in a subfolder com.

So if you create D:\corejava\com, and move A.java and B.java into it, that should do the trick.
 
Hari Kumarkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matthew Brown,

Step 3 is working fine, where I explicitly imported "import com.A;" and "import com.B;". But I want it to run through "import com.*;"
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are usually better with import com.A; than import com.*;, but please supply more details. If import com.A; works, then import com.*; should work too. Is there something peculiar about your folder structure? Have you got some sort of spelling error?
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic