5

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?

6
  • Which version of java you are using? Commented Feb 19, 2015 at 18:13
  • To develop I'm using Java 7 (jdk1.7.0_45), but it is happening on my Sony Xperia device on runtime, not at compile time. Commented Feb 19, 2015 at 18:29
  • What is the api version of your mobile? It is not available below api level 19 Commented Feb 19, 2015 at 20:21
  • I'm using a target level 19. My xperia has 4.1.2 android version. Commented Feb 19, 2015 at 22:21
  • 2
    4.1.2 is api level 16 Commented Feb 20, 2015 at 10:10

2 Answers 2

4

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));
}
Sign up to request clarification or add additional context in comments.

Comments

3

I was wrong. My device was android 4.1, which is api level 16 and the class Objects is since api level 19.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.