Your buildRegisterForm() method must return a Resource, just casting the returned object as a Resource doesn’t actually make it an instance of Resource. It looks like the method returns a FormLayout, so what you need to do is to extend the FormLayout and implement the Resource interface.
public class RegisterForm extends FormLayout implements Resource {
.....
}
Your problem has to do with very basic programming - please search the internet for variable initialization in java, what the value “null” means and what NullPointerException means.