Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Compiling and running

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a problem with compilation .

I have two classes in different packages : packagea and packageb .

package packegea;
public class ClassA {


package packageb;
import packagea.ClassA;

public class ClassB {

public static void main(String[] args) {
ClassA a ;
System.out.println("Got it");

when I try to compile ClassB from parent directoy of both folders packagea and packageb : javac packageb/ClassB
I have this error :
packageb\ error: package packagea does not exist
import packagea.ClassA;
packageb\ error: cannot find symbol
               ClassA a ;
 symbol:   class ClassA
 location: class ClassB

Please help,
Saloon Keeper
Posts: 12419
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You have a typo in the package declaration in ClassA.
Posts: 70625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Compiling from the command line becomes more difficult when you use package names. One way to do it:-On Windows® use \ and on other operating systems change all \s to /. In line 6 note the . rather than \ or /
You will of course have to correct the spelling which Stephan noticed.
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic