您的位置:程序门 -> java -> j2se / 基础类



exception in thread "main" java.lang.nullpointerexception


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


exception in thread "main" java.lang.nullpointerexception
发表于:2007-05-29 23:11:55 楼主
package   yan1;

import   javax.swing.*;
import   javax.swing.table.*;
import   java.awt.*;
import   java.awt.event.*;
//vist   bbs   java
public   class   customer   extends   jframe   {

//   variables   of   labels
jlabel   heading;

jlabel   labelcustno;

jlabel   labelcustname;

jlabel   labelcustsex;

jlabel   labelcustage;

//   variables   for   data   entry   controls
jtextfield   textcustno;

jtextfield   textcustname;

jcombobox   combocustsex;

jtextfield   textcustage;
customer()   {
super( "customer ");
container   con;
con   =   this.getcontentpane();
con.setlayout(new   flowlayout());
//   initializing   textfield
textcustno   =   new   jtextfield(20);
textcustname   =   new   jtextfield(25);
textcustage   =   new   jtextfield();

string   sex[]   =   {   "male ",   "female "   };
combocustsex   =   new   jcombobox(sex);
//   adding   controls   for   customer   number
con.add(labelcustno);
con.add(textcustno);
//   adding   controls   for   customer   name
con.add(labelcustname);
con.add(textcustname);
//   adding   controls   for   customer   sex
con.add(labelcustsex);
con.add(combocustsex);
//   adding   controls   for   customer   age
con.add(labelcustage);
con.add(textcustage);
//   close   the   program   when   close   button   is   clicked
setdefaultcloseoperation(exit_on_close);
setsize(350,   250);
show();

}

public   static   void   main(string[]   args)   {
customer   cust   =   new   customer();
}
}
错误提示为:
exception   in   thread   "main "   java.lang.nullpointerexception
at   java.awt.container.addimpl(unknown   source)
at   java.awt.container.add(unknown   source)
at   yan1.customer. <init> (customer.java:42)
at   yan1.customer.main(customer.java:61)
请哪一位高手帮忙看啊~我调试了好久,小弟现在在学java开发环境是eclipse+myeclipse,jdk1.4
发表于:2007-05-30 00:18:451楼 得分:0
try   一下!!1
发表于:2007-05-30 08:02:252楼 得分:0
看不懂   。   不过看异常的类型     我觉得可能是你用了一个没有指向任何对象的引用吧。。
发表于:2007-05-30 08:24:423楼 得分:0
labelxxx都没有初始化,也要labelxxx   =   new   jlabel( "xxx ")的
发表于:2007-05-30 18:39:364楼 得分:0
con.add(labelcustno);这里没有new一下的都会空指针


快速检索

最新资讯
热门点击