• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Error when comparing to strings

Hi tellblom,

Your code is behaving correctly as Ver and VersionsKoll are different objects, and == tests to see if two variables refer to the same object. It doesn't check if the two objects have the same value. In C/C++ terms it's like comparing two pointers to see if they have the same address, rather than checking to see if they point to data that looks the same.

To compare strings you need to use the "equals" method on one of the strings.

Code:
if ( VersionKoll.equals(Ver) )
{
 . . . they match . . .
}
In general, if the string could be null, then you'd write something like this instead, so you don't call a method on a null object:

Code:
if ( VersionKoll != null && VersionKoll.equals(Ver) )
{
 . . . they match . . .
}
See this page for more information:

Comparing Strings and Portions of Strings (The Java
 
Thanx alot,

As you proberbly understand I usually code in C# and the quite similar to java.

Once again thanx for this.

/M
 
Back
Top Bottom