In two projects that I've contributed I've had this Error:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: java.util.Objects
That because I've implemented hashCode
and equals
methods using Objects
class.
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.image);
hash = 97 * hash + Objects.hashCode(this.car);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SummaryContent other = (SummaryContent) obj;
if (!Objects.equals(this.image, other.image)) {
return false;
}
return Objects.equals(this.car, other.car);
}
When I compile I don't get error or warnings. Why might it be happening?
I have the same problem in my new game. And i think, it happends, because different mobile manufacturer provide phones with different version of jvm.
My solution of this problem was copying implementation of methos equals from Objects to my project. It dirty, but work:
public static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}
I was wrong. My device was android 4.1, which is api level 16 and the class Objects
is since api level 19.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With