if(type.compareTo("fire") == 0)其中type是String型,在什么情况下会报错啊?
具体错误如下:org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 7370:  int second = calendar.get(GregorianCalendar.SECOND);
71:  String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
72:  //String str1 = "fire";
73:  if(type.compareTo("fire") == 0){

解决方案 »

  1.   

    估计是 type = null
    改成 "fire".compareTo(type) == 0 应该就可以了
    原因是可能由于其他地方的语法等问题,导致type没有被赋值
      

  2.   


    这个没有问题啊type的值是什么?
      

  3.   

    type是一个函数的参数,这段代码在函数内部?可能是null问题,
      

  4.   

    还是有问题诶,请看完整代码,谢谢:public void insert(String thing,String type,Statement statement)throws SQLException{
    String query="INSERT INTO Tommorrow VALUES('";
    GregorianCalendar calendar = new GregorianCalendar();
    int year = calendar.get(GregorianCalendar.YEAR);
    int month = calendar.get(GregorianCalendar.MONTH);
    int day = calendar.get(GregorianCalendar.DAY_OF_MONTH);
    int hour = calendar.get(GregorianCalendar.HOUR_OF_DAY);
    int minute = calendar.get(GregorianCalendar.MINUTE);
    int second = calendar.get(GregorianCalendar.SECOND);
    String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
    //String str1 = "fire";
    if(("fire").compareTo(type) == 0){
    query+=date;query+="','";query+=thing;query+="',1,2)";
    statement.executeUpdate(query);
    }
    if(type/*.compareToIgnoreCase("happy")*/ == /*0*/"happy"){
    query+=date;query+="','";query+=thing;query+="',2,2)";
    statement.executeUpdate(query);
    }
    if(type/*.compareToIgnoreCase("workless")*/ == /*0*/"workless"){
    query+=date;query+="','";query+=thing;query+="',3,2)";
    statement.executeUpdate(query);
    }
    if(type/*.compareToIgnoreCase("game")*/ == /*0*/"game"){
    query+=date;query+="','";query+=thing;query+="',4,2)";
    statement.executeUpdate(query);
    }
    }
      

  5.   

    if(type.compareTo("fire") == 0)
    改为
    if("fire".equals(type))
      

  6.   

    compareTo 无论type放在前后 只要type是null都会 报null错
    要不判断null 要不 用5楼的 equals 并且 type必须放后