I have created a FloatingActionButton
object outside methods without giving it any value. Inside the method fabInitializer
, I give it a value by referencing it to tag in the XML file.
When I want to use a method of class's object I've created, Android Studio says:
object.method() may produce a java null pointer exception.
The program runs fine.
If the object value is null
it should produce that message, but it is not. How can I fix this?
public void fabInitializer() {
mFab = (FloatingActionButton) findViewById(R.id.fab);
mFab.setOnClickListener(this);
}