这有什么问题?我找不到符号

时间:2013-10-08 02:00:12

标签: java testing compilation null

这是类的代码方法的前四行:

这是 IN 类'CrudController'

public String create(Object entity, Class clazz, String req_id, HttpServletResponse response) throws NullPointerException {
    if (entity == null ) throw NullPointerException("ENTITY");
    else if(clazz == null) throw NullPointerException("CLAZZ");
            else if(response == null) throw NullPointerException("RESPONSE");

我在这三行中遇到了这些错误:

[ERROR] /path/to/CrudController.java:[42,29] error: cannot find symbol
[ERROR]  class CrudController
[ERROR] /path/to/CrudController.java:[43,31] error: cannot find symbol
[ERROR]  class CrudController
[ERROR]/pathto/CrudController.java:[44,48] error: cannot find symbol
[ERROR]  class CrudController

位置编号(29,31和48在'=='

的开头是正确的

2 个答案:

答案 0 :(得分:5)

将所有throw NullPointerException(STRING);更改为throw new NullPointerException(STRING);

这里你抛出异常。异常是相应的Exception类型类的实例,因此您需要抛出一个需要new关键字的实例。

public String create(Object entity, Class clazz, String req_id, HttpServletResponse     response) throws NullPointerException {
if (entity == null ) throw new NullPointerException("ENTITY");
else if(clazz == null) throw new NullPointerException("CLAZZ");
        else if(response == null) throw new NullPointerException("RESPONSE");

答案 1 :(得分:0)

throw NullPointerException("CLAZZ");不是法律声明。您必须使用new运算符创建NullPointerException

的实例

e.g。

throw new NullPointerException(STRING);