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

Really Frustrated with "main" error message

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A previous post had the same trouble.
I tried following all of the advice.
I think I have the CLASSPATH set correctly.
But I am still having the same trouble.

The .java file does compile and I can see the .class file.
When I attempt to run it in an html window it doesn't work. The errors I get in the Java Console are numerous "at sun.applet.etc...(Unknown Source).
When I attempt to run the program through the dos prompts I get,
"exception in thread "main" java.lang.NoClassDefFoundError: (then the path to the file)."

I have successfully compiled and run other java class files. The only difference I can see here is that I am not beginning the .java file with "import java.smoething.something;"

Any suggestions would be greatly appreciated,
Thank you




public class myfirstapp {

public static void main (String[] args) {
System.out.println("I rule!");
System.out.println("the world");
}
}
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the command you are using to compile it and running it?

also did you set the path variable in windows to point to yuor bin folder of Java installation?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there are lots of ways that could fetch errors. probably you would have set the classpath wrongly.

for eg: set classpath=.;

this means that it shows that .(dot) refers the current working directory. and you are also supposed to put that ;(semi colon) saying that u r terminating the classpath syntax.if you still have it tell us how and wat have u set as ur class path and path.
 
Rob Hermann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'm convinced that my trouble results from an incorrect PATH and/or CLASSPATH.

On my computer(winXP)
I downloaded everything to a folder called java which contains subfolders:
bin, demo, include, jre, lib, .netbeans, src.
My CLASSPATH and PATH are both set to this java folder.

Elsewhere on my computer I have a folder jre.1.5.0_06 that I have never accessed for any of the applets I've made before (i've worked through Howstuffworks.com's java tutorial)

Does this help you help me???

Thanks again,
Rob
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is this the program u are having trouble with??

public class myfirstapp {

public static void main (String[] args) {
System.out.println("I rule!");
System.out.println("the world");
}
}


for this program i dont think u need to set the classpath.. cos there is no import statement.....
just run this program with the following command: java myfirstapp

if the class u want to run is in a package use the following command:
java -classpath "classpath" FileName

else try this : java -cp . myfirstapp

Hope this helps
Regards
Simon
 
Roy Simon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
is the applet running when u use the appletviewer?? if not try adding the applet to a JFrame and implicitly calling the init() and start() method on the applet object.... By using a JFrame u make the applet a normal java application... If the applet is not running in ur browser then you have not installed java properly....
try reinstalling java....

Regards
Simon
 
Rob Hermann
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks for the help so far. This is what is happening now:
1) if I try to use the appletviewer (>appletviewer MyFirstApp) I get "I/O exception while reading ...(The system cannot find the file specified)

2) If I use java -cp . MyFirstApp it WORKS
Why does this work?
How do I use the "java -cp ." if the file is not in the same folder. When I move it back to the folder where I keep my applets I cannot get it to run.

3)I still cannot get it to run in a browser window.
 
Roy Simon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
u can use the java -cp in this way to run files in different locations..
java -cp "path" fileName

ie if ur file is in say c:\myFolder\fileName.class
use the following command...
java -cp "c:\myFolder" fileName

Regards
Simon
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic