-1

I'm attempting to check to ensure the device has a MAC address set using java - however I'm having trouble implementing the check to do so. I've attempted to use the following:

if (MAC == "00:00:00:00:00:00"){


                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityMain.this);
                builder.setMessage("You Have No MAC Address!")
                       .setCancelable(false)
                       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                //do things
                           }
                       });
                AlertDialog alert = builder.create();
                alert.show();

            }

However the condition is never met - even with the value of MAC set to 00:00:00:00:00:00.

I thought this might be the way I am comparing to the two values. So then I tried this:

if (MAC = "00:00:00:00:00:00"){


                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityMain.this);
                builder.setMessage("You Have No MAC Address!")
                       .setCancelable(false)
                       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                //do things
                           }
                       });
                AlertDialog alert = builder.create();
                alert.show();

            }

But I end up with the error: Type mismatch cannot convert from a String to a Boolean.

My question is: What would be the best method of resolving this issue?

2 Answers2

1

Never compare strings with ==. Use .equals() instead.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Use equals() method and check, you will get proper results.

Visit what is the difference between == operator and equals()? (with hashcode() ???) to understand fully the difference.

Community
  • 1
  • 1
Ranjeet
  • 393
  • 2
  • 10