写了个applet,用appletviewer执行是没问题的,但嵌入页面就是访问不了,提示空指针异常,载入java小应用程序失败!

解决方案 »

  1.   

    是不是页面当中applet标签的codebase属性设置有问题,现在的值是.
      

  2.   

    类在这个包下
    package com.applets;页面标签如下
    <applet codebase="." 
                code="com.applets.CallCenter.class" 
                name="CallCenter" 
                width=195 
                height="215">    
        </applet>
    请高人指教
      

  3.   

    把你的applet代码贴出来。
    如果你import了其他的类,这些类也是要一并load到本地的。
      

  4.   

    package com.applets;import java.applet.Applet;
    import java.awt.Button;
    import java.awt.Event;
    import java.awt.TextField;public class CallCenter extends Applet { // 呼叫号码文本框、呼入号码文本框
    private TextField callNumTxt, showNumTxt; // 号码键
    private Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9; // 接听按钮、呼叫按钮、回退按钮
    private Button bAnswer, bCall, bRollback; // 呼出号码、呼入号码
    private String strCall, strAnsuer; public CallCenter() {
    super();
    } public void destroy() {
    // Put your code here
    } public String getAppletInfo() {
    return "This is my default applet created by Eclipse";
    } public void init() { strAnsuer = new String();
    strCall = new String(); setLayout(null); // 设置呼叫号码输入文本框
    callNumTxt = new TextField();
    callNumTxt.setBounds(10, 10, 130, 25);
    this.add(callNumTxt); // 设置呼入号码显示文本框
    showNumTxt = new TextField();
    showNumTxt.setBounds(10, 40, 130, 25);
    this.add(showNumTxt); // 设置呼叫按钮
    bCall = new Button("呼叫");
    bCall.setBounds(145, 10, 40, 25);
    this.add(bCall); // 设置接听按钮
    bAnswer = new Button("接听");
    bAnswer.setBounds(145, 40, 40, 25);
    this.add(bAnswer); // 设置回退按钮
    bRollback = new Button("<——");
    bRollback.setBounds(145, 75, 40, 40);
    this.add(bRollback); // 设置号码按钮
    b0 = new Button("0");
    b0.setBounds(145, 120, 40, 85);
    this.add(b0); b1 = new Button("1");
    b1.setBounds(10, 165, 40, 40);
    this.add(b1); b2 = new Button("2");
    b2.setBounds(55, 165, 40, 40);
    this.add(b2); b3 = new Button("3");
    b3.setBounds(100, 165, 40, 40);
    this.add(b3); b4 = new Button("4");
    b4.setBounds(10, 120, 40, 40);
    this.add(b4); b5 = new Button("5");
    b5.setBounds(55, 120, 40, 40);
    this.add(b5); b6 = new Button("6");
    b6.setBounds(100, 120, 40, 40);
    this.add(b6); b7 = new Button("7");
    b7.setBounds(10, 75, 40, 40);
    this.add(b7); b8 = new Button("8");
    b8.setBounds(55, 75, 40, 40);
    this.add(b8); b9 = new Button("9");
    b9.setBounds(100, 75, 40, 40);
    this.add(b9); } public void start() {
    // Put your code here
    } public void stop() {
    // Put your code here
    } // 根据点击按钮触发事件
    public boolean action(Event e, Object o) {
    // 按号码键
    if ((e.target == b0) || (e.target == b1) || (e.target == b2)
    || (e.target == b3) || (e.target == b4) || (e.target == b5)
    || (e.target == b6) || (e.target == b7) || (e.target == b8)
    || (e.target == b9)) {
    doCallNumTxt((String) o);
    } // 按回退键
    if (e.target == bRollback) {
    doRollback();
    } // 按呼叫键
    if (e.target == bCall) {
    doCall();
    } // 按接听键
    if (e.target == bAnswer) {
    doAnswer();
    } return true;
    } // 点击了号码键后显示到号码输入框内
    public void doCallNumTxt(String s) {
    strCall += s;
    callNumTxt.setText(strCall);
    repaint();
    } // 点击回退键后清除最后一个字符
    public void doRollback() {
    String s = callNumTxt.getText();
    if (s.length() != 0) {
    s = s.substring(0, s.length() - 1);
    callNumTxt.setText(s);
    strCall = s;
    repaint();
    }
    } // 点击呼叫按钮时候
    public void doAnswer() {
    System.out.println("开始呼叫...");
    } // 点击接听按钮时
    public void doCall() {
    System.out.println("开始接听...");
    }
    }
      

  5.   

    我在本地尝试了一下,可以载入(我没尝试功能,但是界面出来了)。
    我觉得有可能是你的路径的问题,建议你把package部分都去掉,然后重新编译你的代码。
    然后把CallCenter.class文件和你的html放在一起,再尝试一下。
      

  6.   

    不用的,你用的都是jre默认的包。可能是你的目录结构组织的有问题。
    你那个异常,我看也不大可能是空指针。