Click to See Complete Forum and Search --> : Class not found


daileyps
October 3rd, 2000, 09:15 AM
Frustrated...no matter what I do, I get class not found errors. Can someone explain to this newbie how to let java know where things reside? I have an html file, that has my applet name in the code parm of my applet tag...no problems there, it's when my applet class file tries to do something contained in another one of my classes that I have the problem, can't find any of my classes and they are all in the same directory. Do I need a package? How does that work? What am I doing wrong??? Argh#)$&@#)%(&#@)

zaBulet
October 3rd, 2000, 09:55 AM
Hmmmm!!!
If you have all the files you need in the same directory JVM should be able to find the class beacause you create a default package (this is when you don't specify a package)
Have you configured your CLASSPATH enviroment variable?
If you don't then do it!!!
When JVM look for a specified class first it checks the CLASSPATH variable.
So..if you have for example all your .class files in ClassFilesDirectory for example you go in Autoexec.bat file and add the next piece of code:

SET CLASSPATH = C:\YourPathToClassFilesDirectory...\ClassFilesDirectory
in Windows
or
export CLASSPATH = /YourPathToClassFilesDirectory.../ClassFilesDirectory
in Linux
If your class files are packaged in a .jar file then you do the same thing like above :
SET CLASSPATH = C:\YourPathToJarFile....\YourJarFile.jar

If you haven't configured your CLASSPATH variable your JVM won't be able to find your .class files.
Of course..is no problem with the compiler...it doesn't need that your CLASSPATH variable to be configured.

Or...maybe you your class is not declared "public"(i'm not sure if with applets works...but once i had the same problem with a servlet)

So...try these!!!

daileyps
October 3rd, 2000, 10:06 AM
Thanks for the response, but I don't think my CLASSPATH is the issue. I can run everything fine as an application. I'm only having trouble with applets.

Gurinder Grewal
October 3rd, 2000, 01:36 PM
My guess is that you are using Swing libraries in your applet. If that is the case then you cannot use <applet> tag in your HTML to run the applet. You will have to change the HTML code to use <OBJECT> tag. Here is example, assuming the applet class name is "testApplet.class"

NOTE: The following code is tested with IE and it works.

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
height="100"
width="200"
codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="testApplet.class">
<PARAM NAME="codebase" VALUE=".">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
</OBJECT>


NOTE: The following code should work with both Netscape and IE but I have not tested it:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
height="100"
width="200"
codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,2,0">
<PARAM NAME="code" VALUE="testApplet.class">
<PARAM NAME="codebase" VALUE=".">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
<COMMENT>
<EMBED
type="application/x-java-applet;version=1.2.2" CODE = "testApplet.class"
CODEBASE = "."
WIDTH = 170
HEIGHT = 150
pluginspage="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,2,0">
<NOEMBED>
</COMMENT>
</NOEMBED>
</EMBED>
</OBJECT>

Good Luck!