• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Error  RSS feed

 
Henry Wallace
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created ClassA and ClassB Java modules in packages atlantic and pacific, respectively. I also ensured that both packages were in the CLASSPATH.

ClassA is as follows:




ClassB is as follows:



I then successfully compiled both modules from the oceans folder (which is a level above the atlantic and pacific folders).

I then attempted to run the ClassB class as follows:

java pacific.ClassB

I received the following error:



Yet the ClassB.class object does exist in the pacific folder. Please indicate the cause of the error.

Thanks.

Henry

[Moderator edit: added code tags]
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always use the code button and indent your code correctly. Don't double‑space everything.
Don't mess around with the CLASSPATH. Put the two folders in the appropriate locations and you can forget about the CLASSPATH. Why have you got an oceans folder? What do you get when you run the dir or ls commands from your current location? You shou‍ld be in the oceans folder, so you should see atlantic and pacific in that folder.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wallace wrote:I created ClassA and ClassB Java modules

One note before you get a habit. Better not to use IDE specific terminology. For many term 'module' means nothing. I presume you're referring to IntelliJ modules. If you were to pick another IDE, they might would call it 'Project', and if NotePad++ there won't be anything like that. That could confuse yourself later if you'll be forced to use another IDE. The right terminology is just a 'class'. In fact, don't name your class 'ClassA', should be enough to name it for test purpose just A and B, otherwise you duplicating code as there is a 'class' keyword you use already.

So, instead:

This:

And ideally:
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing.

From the way you named your packages, it suggests that you misunderstanding the purpose of packages. I might mistaken what you mean, but:
It seems ocean types you're going to distinct by differentiating packages, I don't think that is correct.

What more correct probably would be:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!