Topic: 请帮我看一看这段代码! (可以不理,已解决)

  Print this page

1.请帮我看一看这段代码! (可以不理,已解决) Copy to clipboard
Posted by: q_yuan
Posted on: 2004-11-09 10:35

import java.awt.*;
import java.awt.event.*;
public class TesttingMenu implements WindowListener{
  private Frame f;
  private MenuBar mb;
  private Menu m1,m2,mhelp;
  private MenuItem mi11,mi12,mi13,mi21,mi22,mihelp;
  public TesttingMenu(){
   f.addWindowListener(this);
   f= new Frame("Testing Menu");
    mb = new MenuBar();
    m1 = new Menu("文件");
    m2 = new Menu("编辑");
    mhelp = new Menu("帮助");
    mi11 = new MenuItem("新建");
    mi12 = new MenuItem("打开");
    mi13 = new MenuItem("保存");
    mi21 = new MenuItem("查找");
    mi22 = new MenuItem("工具");
    mihelp = new MenuItem("帮助文件");
    m1.add(mi11);
    m1.add(mi12);
    m1.add(mi13);
    m2.add(mi21);
    m2.add(mi22);
    mhelp.add(mihelp);
    m1.add(m2);
    mb.add(m1);
    mb.setHelpMenu(mhelp);
    f.setMenuBar(mb);
    f.setSize(200,200);
    f.setVisible(true);
    }
    public static void main(String[] args){
      TesttingMenu tm = new TesttingMenu();
            }
  public void windowActivated(WindowEvent e){};
  public void windowClosed(WindowEvent e){};
  public void windowClosing(WindowEvent e){System.exit(1);};
  public void windowDeactivated(WindowEvent e){};
  public void windowDeiconified(WindowEvent e){};
  public void windowIconified(WindowEvent e){};
  public void windowOpened(WindowEvent e){};
  }

这段代码可以编译过去,为什么执行起来就有问题? 提示说是:
Exception in thread "main" java.lang.NullPointerException
at TesttingMenu.<init><TesttingMenu.java:9>
at TesttingMenu.main<TesttingMenu.java:35>

请问这是什么原因?要怎么解决?谢了!

2.Re:请帮我看一看这段代码! [Re: q_yuan] Copy to clipboard
Posted by: nothing
Posted on: 2004-11-09 10:40



3.Re:请帮我看一看这段代码! [Re: q_yuan] Copy to clipboard
Posted by: q_yuan
Posted on: 2004-11-09 10:43

谢谢上面的兄弟了!
我改过来了!

4.Re:请帮我看一看这段代码!了 (可以不理,已解决) [Re: q_yuan] Copy to clipboard
Posted by: why
Posted on: 2004-11-10 08:53

NullPointerException!!

很直接地说:
这样的问题,自己也不能解决的话,请好好从头学起。
不要浪费版面和大家的时间。

请尽量用准确的文字描述作为标题
否则这样的标题,见即删!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923