Applet查看器运行时错误。 Appletviewer无法打开

时间:2014-09-14 17:19:13

标签: java applet runtime-error appletviewer

import java.awt.*;
import java.io.*;
import java.applet.*;
/*<applet code = App width=400,height =400>
</applet> */
class App extends Applet
{
    String str = " ";
    public void init()
    {
        str= "from int method";
        System.out.println(str);
        repaint();
    }

    public void start()
    {
        str= "from start method";
        System.out.println(str);
        repaint();
    }

    public void stop()
    {
        str= "from stop method";
        System.out.println(str);
        repaint();
    }

    public void destroy()
    {
        str= "from destroy method";
        System.out.println(str);
        repaint();
    }
    public void paint (Graphics g)
    {
        g.drawString(str, 200, 200);
    }
} 

这是终端的输出

    sumedh@sumedh-h9-1325in:~$ appletviewer App.java
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/java/jdk1.8.0_05/jre/lib/i386/libawt_xawt.so: libXrender.so.1: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1814)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1083)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1835)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1119)
    at java.awt.Toolkit$3.run(Toolkit.java:1651)
    at java.awt.Toolkit$3.run(Toolkit.java:1649)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.loadLibraries(Toolkit.java:1648)
    at java.awt.Toolkit.<clinit>(Toolkit.java:1683)
    at java.awt.Component.<clinit>(Component.java:595)
    at sun.applet.Main.run(Main.java:156)
    at sun.applet.Main.main(Main.java:98)

我该怎么办?我似乎无法弄清楚我的代码或安装的jdk有什么问题。请帮我解决这个问题。我甚至尝试通过从.java文件中删除applet代码并创建一个html文件来单独使用html,如下所示。我的所有浏览器都无法加载插件。这是浏览器问题还是appplet的问题? HtML代码:

<html>    
<head>
<title>ABCD</title>
<applet code  = App width=200 height=200>
</applet>
</html>

1 个答案:

答案 0 :(得分:0)

您的整个代码似乎没问题。这里的问题在于标签。 将.java文件的名称放在双引号中,即使用如下

       code = "App" width=400,height =400