Reputation: 757
This is the top four lines of the code method of a class:
This is IN the class '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");
I'm getting these errors for these three lines:
[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
The postion numbers (29, 31, and 48 are RIGHT at the beginning of '=='
Upvotes: 1
Views: 1241
Reputation: 5110
change all throw NullPointerException(STRING);
to throw new NullPointerException(STRING);
Here you are throwing the exception. Exception is instance of corresponding Exception type class so you need to throw an instance that why new
keyword is needed.
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");
Upvotes: 5
Reputation: 11841
throw NullPointerException("CLAZZ");
is not a legal statement. You must use the new
operator to create an instance of the NullPointerException
e.g.
throw new NullPointerException(STRING);
Upvotes: 0