Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error when using package

 
Matthew Paul
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I'm new to the forums, so thanks for letting me join in on the fun! I've been programming java for about 4 months now.

My problem seems to be the way I'm trying to tell my java to run a class in a package. Whenever I try to run my VehicleTest.class file from my terminal I get the following error:



As you can probably tell, I'm using Ubuntu Linux (Natty). I'm almost certain that my java is set up correctly, due to when I use the command "java -version" it pops up with"
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)"

I can run programs that are not in a package, or in the default package with no problem. I know that my code is correct because I use Eclipse IDE and it gives no errors and runs perfectly in the internal console.

I don't really know how to show the hierarchy of my files, but here goes.

Workspace
Starting out with Java
bin | src
practice | practice
VehicleTest.class | VehicleTest.java

The class is part of the package practice. I've been searching for an answer for about an hour and a half ( ) with no luck. I'm pretty sure it's a simple answer and that's why it's so frustrating to me. If you want it, here's the code dump from my files. Thanks so much (in advance) for helpin' me out!

Vehicle.java


VehicleTest.java

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify the full class name, while the parent of the package's root folder is on the class path. In this case, go back to the bin folder and run the code as java practice.VehicleTest.
 
Matthew Paul
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wow... yeah, that was a super easy thing to do... Thank you very much for answering so promptly Rob! I will remember that as I continue learning more about using packages and such.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Matthew
 
Matthew Paul
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the welcome Mr. Venkatasamy!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic