试试这个public String test (int s){
 if (s != null){
  try{
     sql="select from table where id="+s;
   ...............
   .............
   }catch(Exception e){
      System.err.outprintln(e.toString());
   }
 }else{
   System.err.outprintln("int is null");
 }
}

解决方案 »

  1.   

    如果这么简单就好了,int型变量能之接与null比较吗,我的编辑器通不过!
    if (s!=null)
    或者
    if (s==null)
    都不可以,提示为Operator!=can not applied to int,null
      

  2.   

    举个例子,比如登录的用户ID值为2,我的判断用户的类为
    public String test (int id){
    ....
    ....
    return str;
    }但用户一旦超时后,它的ID不是null了吗,这时程序当然会报错啊
      

  3.   

    int不会是null的,int是什么值取决与你如何调用这个方法
    程序报错不会是因为int的值问题,int即使不初始化,默认为0
      

  4.   

    有没有搞错!int还要和null比较!不初始化 int 为 0
      

  5.   

    当你调用这个方法的时候一定要给出参数id的值,这时候id值不能为null.
    [用户一旦超时后,它的id不是null了吗]这句话好象不成立.
      

  6.   

    //[用户一旦超时后,它的id不是null了吗]
    指在session中,id就可能为null
      

  7.   

    int 是不是空的。null 类才有这个值int i;
    此时i是0;
      

  8.   

    //[用户一旦超时后,它的id不是null了吗]
    指在session中,id就可能为nullto:楼主
    你确定id为int型?
    public abstract Object getAttribute(String name)
    getAttribute方法的Attribute Type是String型的呀。
    参见
    http://java.sun.com/products/servlet/2.1/api/javax.servlet.ServletRequest.html
      

  9.   

    在jsp文件中代码为:
    <%
    String id=sys.getSessionInfo(session,"UserID");
    out.print(sendFile.getSendedFile(Integer.parseInt(id)))%>
    在sendFile.java这个bean中:
     public String getSendedFile(int userID) {
            String sql;
            int i=0;
            String str = "";
            try {
                sql = "select * from SendFile where documented is null and userFrom=" + userID;
                DBConnectionManager dm = DBConnectionManager.getInstance();
                Connection con = dm.getConnection("gsweb");
                Statement stmt = con.createStatement();
                Statement stmt1 = con.createStatement();
                ResultSet rs = stmt.executeQuery(sql);
                ......
                ......
                ......
                dm.freeConnection("gsweb", con);
                dm.release();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
            return str;
        }如果用户没有登录之接运行jsp页,提示错误为
    Internal Servlet Error:
    javax.servlet.ServletException: nullRoot cause:
    java.lang.NumberFormatException: null
      

  10.   

    int类不可能为null, null只适用于Ojbect类型而不适用于基本类型,不信试试着个:
      

  11.   

    int number = null;
    系统一定会报错。但如果用object类型(java API类或用户定义类)就可以用null:
    Object myObject = null; 将会通过编译。如果一定要用整型变量且用null表示为空,可用int的wrapper class Integer定义整型变量,具体如下:
    Integer number = new Integer(9); 这样,当number没有被初始化或因某种原因丁一直为空时,就会返回null.
      

  12.   

    我开始做java的时候也为这个问题头痛,后来干脆使用Integerpublic String test (Integer s)
      

  13.   

    <%
    String id=sys.getSessionInfo(session,"UserID");
    out.print(sendFile.getSendedFile(Integer.parseInt(id)))
    %>
    -------------------------------------------在String id=sys.getSessionInfo(session,"UserID");这句后加判断
      

  14.   

    最笨的方法,可以这么做:
    if((s+"").equals("null"))......
      

  15.   

    你的出错信息是由于 Integer.parseInt(id) 造成的,而并非 sendFile.getSendedFile() 方法造成的,因为id为空值,不能转换为整型.
      

  16.   

    也就是说,如果session过期,你执行以下一句就会出问题,
    int id=Integer.parseInt(sys.getSessionInfo(session,"UserID"));