I'm trying to get appletviewer to work with a very simple Hello program. Here's my code for test.java

import java.applet.*;
import java.awt.*;

public class test extends Applet {
    public void paint(Graphics g)  {
        g.drawString("Hello",123,125);
    }
}

Then I wrote the following html. Here's my code for test.html

<applet code = "test" width = 300 height = 300>
</applet>

When I execute the command: appletviewer test.html Everything works great.

I run into trouble when I try add a package label at the top of my java file. Line #1 starts with:

package applet;

I find I can't get the appletviewer to work. I get an error that reads:

java.lang.NoClassdefFoundError: test (wrong name: applet/test)

From a book I'm reading (Core Jave, Volume I - Fundamentals) I see that I should change my html file as follows (adding applet/ before the name test):

<applet code = "applet/test" width = 300 height = 300>
</applet>

Now I get the error:

load: class applet/test not found.

I suspect my problem is in my html syntax but I can't figure it out. I've tried applet.test, applet//test and several others but nothing works. How can I get appletviewer to recognize my applet if it has a package name?

    import java.applet.*;
    import java.awt.*;
    /*
    <applet code="test" height=500 width=500>
    </applet>
    */
    public class test extends Applet {
    public void paint(Graphics g) {
    g.drawString("Hello",123,125);
    }
    }

I have just added this comment block /* */ and it worked for me,and yes it will ask for class expected if you remove this block.

"Mark this thread as solved Thank You And Keep Coding"

More info. I have all my files, test.html, .java, .class sitting in Windows 7 directory; C:\temp5. That's where I run everything. I suspect I need and applet directory perhaps, but I've tried countless combinations and can't get this to work. Without a package statement in my code I'm fine. With it my program won't run. Where should my files reside? What directory should I run appletviewer from? Thanks

Is it your first applet program?
First of all you must have an appletviewer in your directory i.e.,(C:\Program Files\Java\jdk1.7.0_03\bin) check for it.
For your first program just put all your data into this directory only and try to execute a program and once you are used to with "set path" and other methods then use your desired directory for execution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.