充值卡类型名称
       <select id="ctName">
       <option value="0">全部</option>
       <%
       List<TCardTypeEntity> ctList=(List<TCardTypeEntity>)request.getAttribute("tcteList");
       if(ctList!=null && ctList.size()!=0){
       for(TCardTypeEntity tcte : ctList){
       if(tcte.getName()!=null){
       %>
       <option value="<%=tcte.getName()%>"><%=tcte.getName()%></option>
<%
}
}
}
%>
       </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
数据库中有两条记录,如下
select * from tcard_type where name is NULL;id   name tetmemo int1 AllowSale
137  null null    null     0
138  null null    null     0控制台报错如下:
[11:07:54,250] [InsertTag$InsertHandler,922] - ServletException in '/umanage/minstall/cardInstall.jsp': null
org.apache.jasper.JasperException: An exception occurred processing JSP page /umanage/minstall/cardInstall.jsp at line 5451:         List<TCardTypeEntity> ctList=(List<TCardTypeEntity>)request.getAttribute("tcteList");
52:         if(ctList!=null && ctList.size()!=0){
53:         for(TCardTypeEntity tcte : ctList){
54:         if(tcte.getName()!=null){
55:         %>
56:         <option value="<%=tcte.getName()%>"><%=tcte.getName()%></option>
57: 
  <%
是不是在.jsp页面 tcte.getName的值不能为null????把数据库中的这两条记录删除了,刷新页面就可以显示页面,请高人指点,谢谢!

解决方案 »

  1.   

    神奇的错误,看起来似乎是 tcte 本身是NULL,你可以在if前面先System.out.println输出出来检查看看。
      

  2.   

    tcte.getName()!=null
    换成
    null!=tcte.getName()
    试一试
      

  3.   

    tcte应该是null,null.getName()报错。估计是这样。检查你的list是不是加入一个未赋值的对象。
      

  4.   

    if(tcte!=null){
    %>
    <option value="<%=tcte.getName()%>"><%=tcte.getName()%></option>
    <%
      

  5.   

    楼主在跳getName方法的时候线判断tcte对象是否为空
      

  6.   

    tcte.getName()!=null 这样写 和 这样写 null!=tcte.getName() 是一样的,而且也试过了,依然是报上面的那个错误,tcte不可能为null的,插入到数据库中的数据,id(标识列)是有值的,其它字段可以为null,如下所示:
    CREATE TABLE `tcard_type` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(50) default NULL,
      `txtmemo` varchar(100) default NULL,
      `int1` int(11) default NULL,
      `AllowSale` int(11) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312所以tcte.getName();有时候会null!但是tcte.getName()
      

  7.   

    tcte.getName() 为 null,不会任何错误,不是这里的问题。你自己试试看:
    String a = null;
    if (a == null) {
      System.out.println(a);
    }问题只能是 null值 被调用了,类似于让JVM执行: null.getName();