Answer the question
In order to leave comments, you need to log in
Error when comparing two strings in Java(Android)?
I'm trying to compare two strings (it would seem: what could be simpler?).
if(!(movie.getLanguage().equals(specifications.language))) {
return false;
}
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Answer the question
In order to leave comments, you need to log in
Obviously movie.getLanguage() == null.
Or the error is not in this line.
You can use Objects.equals()
And it is possible to compare through compareTo.
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials", str2 = "point";
// компаратор выдает число 0 - если равны +n - если первое больше второго и -n - меньше второго;
int retval = str1.compareTo(str2);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question