Reputation: 734
I want to test my application using Find Bugs plugin for eclipse and I get this kind of bug:
Unchecked/unconfirmed cast from android.view.View to android.widget.EditText of return value
and code part is this:
((EditText) findViewById(R.id.EditText)).setEnabled(true);
So what is the bug? I tried to write like this:
if(findViewById(R.id.otherEditText) instanceof EditText)
((EditText) findViewById(R.id.otherEditText)).setEnabled(true);
But there is no result , the same bug is appeared
Upvotes: 2
Views: 685
Reputation: 17494
The problem is that FindBugs cannot be sure that the method call gives the same result every time. So it must assume that the result is different in the test and where the cast happens.
In order to give this information to FindBugs, try this:
findViewById(R.id.otherEditText)
to a temporary variable without casting.if
and the cast using the variable.This way, FindBugs can see that the value checked and the value used are the same.
Upvotes: 3