Question

I am currently creating an app which uses location based variables and for arguments sake, I want to take in the string which is assigned from getThoroughfare() and afaik, it's a String according to the API but lets say I do this

class Game extends MapActivity{

public random function(){
if(addresses!= null){
    Address address = addresses.get(0);
    this.locationText.append("\n" + address.getThoroughfare() + ", " + address.getLocality());  
        userLoc = address.getThoroughfare();
        System.out.println(userLoc);
        }
}

This works and will print out the name of the Street but within another class, if I check it like

if(Game.userLoc == myStreetString){
//do stuff
}

it will not work, let I have insured the strings matched, what gives? Any help would be great

Was it helpful?

Solution

You should use equals instead of == for comparing strings.

if(Game.userLoc.equals(myStreetString)){

OTHER TIPS

try to use the following code

if(Game.userLoc.contains(myStreetString)){

for next time please read the API documentation for Address on address Doc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top