-1

i am doing an application in eclipse which is Position localization for smart phone based on wifi signal, briefly three reference points (routers) need to be used to find my device location and each router has to have a fixed coordinates, i want to use if and if else to select only three routers among the existing Wifi signals and given them a coordinates.

i tried to do it in this way but i did not work?

if  (SSID = router name)   // where SSID is the router user name in eclipse 
{

    int x1 = 0;
    int x2 = 0;

} 

any suggestions please ? thank you

tariq
  • 1
  • 3
  • 3
    Are `SSID` and `routername` String values? If so, you must read [How do I compare strings in Java?](http://stackoverflow.com/q/513832/2024761). – Rahul Apr 30 '14 at 06:40
  • Try to extract the BASIS of your quesiton. Remove all the padding related to the Position localization, which is completely irrelevant for your question, and on other side add a little bit more code so it is clear what does not work. – Honza Zidek May 03 '14 at 17:14

3 Answers3

4

single equal to (=) assign value.

double equal to (==) compare reference not value.

.equals() compares value

so in your case you need to use .equals().

if (SSID.equals(router_name)) {
int x1 = 0;
int x2 = 0;
}
Waqar Ahmed
  • 5,005
  • 2
  • 23
  • 45
1

As long as you define the variables:

int x1 = 0;
int x2 = 0;

inside a block (the if block) they are gone as soon as you leave the if block. Hence, if you want to preserve the assigned values, you have to declare them as fields of your object instance like this:

public class Position {
    private int x1;
    private int x2;

    public void setPosition(String ssid) {
        if (SSID.equals("my router name")) {
            x1 = 0;
            x2 = 0;
        }
    }
}

But I did not catch what your really want to do. Your code snipped and description are to thin In my opinion.

Harmlezz
  • 7,972
  • 27
  • 35
0
if (SSID.equals(routerName))

try the above.

When you compare Strings, use equals, equals compare the value, == compares the reference

Orhan Obut
  • 8,756
  • 5
  • 32
  • 42