Avatar billede fredand Forsker
19. marts 2003 - 09:21 Der er 5 kommentarer og
1 løsning

Problems with Applets

Hello!

I try to write/learn about applet with Suns tutorial.

But I cant get the Simple.java (applet) at sun to work in my browser.

But it work with appletviewer.

The Simple.class and the simple.html file is in the same map.

The In the JavaKonsole in IE I get this message:
Error loading class: Simple
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: Simple
    at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
    at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
    at com/ms/applet/AppletPanel.securedClassLoad (AppletPanel.java)
    at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
    at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
    at com/ms/applet/AppletPanel.run (AppletPanel.java)
    at java/lang/Thread.run (Thread.java) 
The simple.html file looks like this:
<HTML>
    <HEAD>
    </HEAD>
    <BODY>
        <APPLET CODE="Simple.class" codebase="C:\fredrik\javalabb" WIDTH=500 HEIGHT=20>
        </APPLET>
    </BODY>
</HTML>
I had tried both with and without codebase, relative and absolute.

And the Simple.java looks like this:
/*
* 1.1 version.
*/

import java.applet.Applet;
import java.awt.Graphics;

public class Simple extends Applet {

    StringBuffer buffer;

    public void init() {
    buffer = new StringBuffer();
        addItem("initializing... ");
    }

    public void start() {
        addItem("starting... ");
    }

    public void stop() {
        addItem("stopping... ");
    }

    public void destroy() {
        addItem("preparing for unloading...");
    }

    void addItem(String newWord) {
        System.out.println(newWord);
        buffer.append(newWord);
        repaint();
    }

    public void paint(Graphics g) {
    //Draw a Rectangle around the applet's display area.
        g.drawRect(0, 0,
          getSize().width - 1,
          getSize().height - 1);

    //Draw the current string inside the rectangle.
        g.drawString(buffer.toString(), 5, 15);
    }
}

But when I try it online at suns site with IE at: http://java.sun.com/docs/books/tutorial/applet/overview/lifeCycle.html
...it works.

MY IE is version 6.0.2...
Avatar billede arne_v Ekspert
19. marts 2003 - 09:59 #1
I am definattely not an applet expert, but the following looks
suspect to me:

codebase="C:\fredrik\javalabb"
Avatar billede fredand Forsker
19. marts 2003 - 10:03 #2
Hello!
Arne I have tied both with codebase and without.
codebase="C:\fredrik\javalabb"
and put it in an mapp below like
codebase="/myapplets"

But it will not start anyhow.

I open it in my browser like C:\Fredrik\Javalabb\simple.html.

But If I try to Suns example, online, that one works, but not mine.

Does it matter if it online or local??

Fredrik
Avatar billede fredand Forsker
19. marts 2003 - 10:04 #3
...more correct:
I have tied both with codebase and without.
codebase="C:\fredrik\javalabb"
and put it in an map below like
codebase=myapplets/
...sorry
Avatar billede =maddog= Nybegynder
21. marts 2003 - 09:45 #4
try to download the class file from Sun's site. If it works with that file instead of yours, the main problem is your compiler. If not the main problem is your tag definition.
Avatar billede fredand Forsker
21. marts 2003 - 12:48 #5
Hello!
I did as you said and it worked.
But how can that be possible?
Compile once and run every where is the main advantage about Java, isn't it?
So if you can explaine it for me please do!
Make it an answer so I can give you the points!
Best regards
Fredrik
Avatar billede fredand Forsker
28. marts 2003 - 12:42 #6
Hello!

The main problem was that the class-files was uploaded as ascii instead of binary-mode.

Best Regards
F
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester