?
Solved

Package

Posted on 2004-11-22
9
Medium Priority
?
191 Views
Last Modified: 2010-03-31
Hi guys - kinda wierd issue i'm having.

I have a java source file called Start.java in a folder called program (just in windows)

Start.java has like 8 or 9 classes in it plus one class called Start.java with the main( ) method.

I want all these class files to be part of a package called utilstuff

At the "beggining" of Start.java source code file i type (on the first line)
package utilstuff;

Now I compile it. In my program folder I see the Start.java file, and a folder calld utilstuff, with all my class files in it - just fine.
So compiles fine.

When i go to run it - it gives me an error
Exception in thread "main" java.lang.NoSuchMethodError: main
Press any key to continue...

Without the package statement it compiles and runs just fine.

Thanks kindly
0
Comment
Question by:pauldhadialla
  • 4
  • 3
  • 2
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12651072
how do u run it? should be something like:

java utilstuff.Start
0
 

Author Comment

by:pauldhadialla
ID: 12651091
objects - the class file which contains the main method is called Start.java - so I go javac Start.java to compile it and then java Start to run it
0
 
LVL 92

Expert Comment

by:objects
ID: 12651094
you need to specify the fully qualified classname to run class ie. you need to include the package name

java utilstuff.Start
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:vikraman_b
ID: 12651179
also when u want to compile java from different packages like
com.test1
under which some 10 classes
com.test2...etc
under which some classes..
At that time if u want to compile
use
javac -d . *.java
 thats means -d for package options and . for put the classes in the current directory or u can specify the path u want to put.

so if u runnig this commond in the currrent directory say c:/temp

under c:/temp u can see a new folder created com/test1/*.class and com/test2/*.class files

so if u want to run..
what objects said the same ..run the class which has main method
java com.test1 xxx
or java com.test2 YYY
0
 
LVL 3

Expert Comment

by:vikraman_b
ID: 12651188
java com.test1.xxx
or java com.test2.YYY
0
 
LVL 3

Expert Comment

by:vikraman_b
ID: 12651194
Better download IDE it will do for u...
u can go  for
http://www.eclipse.org/downloads/index.php
its free only
0
 

Author Comment

by:pauldhadialla
ID: 12660306
Hi guys. Still getting the same issue. hmmm

I have my main Start.java sitting in a folder called  'program' (doesn't really matter what its called, its just on windows in this folder - nothing else in there)

At the top of the package it says:
package utilstuff;

I compile it - it compiles - creates a folder called utilstuff inside the program folder.

Now i go into the dos prompt and from the program folder run utilstuff.Start  AND also tried going into utilstuff folder and running Start from there.

Still something fishy.

I wonder if i have something with 'access' modifiers messed up - should all the classes have public methods only - and what about variables

Thanks kindly
0
 
LVL 92

Expert Comment

by:objects
ID: 12660419
u better post your code
0
 
LVL 3

Accepted Solution

by:
vikraman_b earned 2000 total points
ID: 12661439
download eclipse it will automatically configure ..
just create a new class and press the run button..it will compile and run for u..
try this
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question