• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Package Compilation

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two classes on under package one outside pacakge.

package com.xyz.abc;

class Test1
{
Test1()
{
System.out.println(" Test 1 ");
}
}

I could able compile this javac -d . Test1.java

Package structure is created and class file is placed.

I have another class which tries to use this class but that class has no package structure and trying to import the Test class


import com.xyz.abc.*;
class Test
{
Test()
{
System.out.println("Testing ");
}

public void add(Test1 aTest)
{
System.out.println("a Testing ");
}
}

I am getting

D:\Testing>javac -classpath D:\Testing\com\xyz\abc Test.java
Test.java:1: package com.xyz.abc does not exist
import com.xyz.abc.*;
^
Test.java:9: cannot access Test1
bad class file: D:\Testing\com\xyz\abc\Test1.class
class file contains wrong class: com.xyz.abc.Test1
Please remove or make sure it appears in the correct subdirectory of the classpath.
public void add(Test1 aTest)
^
2 errors


May I know Why this is giving error.

Thanks
Srinivas Ivaturi
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
javac -classpath D:\Testing Test.java

You're supposed to point javac to the top of your directory structure. javac will see the "import com.xyz.abc.*;" statement and find D:\Testing\com\xyz\abc\Test1.class
[ November 19, 2004: Message edited by: Mike Gershman ]
 
Srinivas Ivaturi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried as you said even that is giving same problem for me.

 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please display the full directory paths of Test1.class and Test.java and post them here.

Also, please post the exact javac command you used on Test.java.
 
Pay attention! Tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic