This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError when trying to run an applet

 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm new to java and am having a problem when I try to run an applet. It compiles OK, but when I try to run it using the appletviewer the console window shows this message:
java.lang.NoClassDefFoundError: HelloApplet (wrong name: fund2/lesson1/HelloApplet)
The last bit (fund2/lesson1) is the last bit of the path to the HelloApplet.
and the applet window shows:
Start: applet not initialized
The code for the applet is:

The code for the html is:

Not even the H1 title appears in the applet window.
The Classpath variable does contain the path to my applet folder and both the class and html files are in the same folder under this path.
I hope someone can suggest where I'm going wrong as I've been tearing my hair out trying to get this working.
Thanks in anticipation.
Debbie-Leigh
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What platform are you on, and what version of java? (Type java -version at a command prompt).
I entered your applet Java code in a file named HelloApplet.java and it compiled fine. I then entered your HTML code in a file named HelloApplet.html. Both files were in the same directory. I then typed "appletviewer HelloApplet.html" at the command prompt. The current directory contained both "HelloApplet.class" and "HelloApplet.html". The appletviewer ran and correctly displayed the applet with the message "Hello World!".
I'd say you have some slight configuration problem, because the code seems to be correct.
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
I'm using WinXP Pro, the JRE is 1.4.2 and the SDK is 1.4.0.
Yes, I suspected it might have something to do with my setup, but I just can't figure out what it could be. I've tried all sorts of ideas from the forums, but nothing seems to work. It still says "wrong name" and gives the last bit of the path to my applet. I don't know why it only shows that bit rather than the full path. Running it through the appletviewer from the command prompt also gives the same error.
Could you suggest anything I could try to correct my set up? (Java applications still run perfectly, though).
My Classpath contains: .;E:\Web\Web Projects\Java
Thanks.
Debbie
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.NoClassDefFoundError: HelloApplet (wrong name: fund2/lesson1/HelloApplet)
The last bit (fund2/lesson1) is the last bit of the path to the HelloApplet.
... My Classpath contains: .;E:\Web\Web Projects\Java

Which directory are you in when you try to run the applet?
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
I use textpad so it uses the same directory that the html and class files are in.
Debbie
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have HelloApplet.java (which compiles just fine using Control-1) and helloapplet.html. Two files, both in the same directory (C:\...\fund2\lesson1). Then you hit Control-3 and choose helloapplet.html from the dropdown choices. Interesting. I get the applet, not an error.

If you go (in TextPad) to Configure --> Preferences --> Tools --> Run Java Applet, do you see
Command: appletviewer
Parameters: $BaseName
Initial Folder: $FileDir
??
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
In Preferences, I have:
Command: appletviewer.exe
Parameters: $BaseName
Initial Folder: $FileDir
which is slightly different, but I don't think the .exe would make any difference would it?
Debbie
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way I can reproduce your error is to put a package statement at the top of the applet.

But you don't have a package statement at the top of your code, so I'm confused.
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
Wow, that's it. I just knew it would be something so simple.
I did put a package name there as one of my tests to try and get it working, but I had commented it out, so I didn't think any more of it. Now I've deleted it, it works a treat.
How very strange!?
Thank you so much for helping.
Debbie
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, another thought ... does that mean that applets can't be members of a package as I haven't read anything yet pointing this out?
Debbie
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An applet can be part of a package, but then you have to account for it when you write the html. For example:
<APPLET CODE="com.macfaq.greeting.HelloWorldApplet"
WIDTH=200 HEIGHT=200>
</APPLET>
 
Debbie Figg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes, I suppose that's the other thing that would have made it work - duly noted.
Thanks again.
Debbie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic