简体   繁体   中英

Wrong 2nd argument type. Found 'java.lang.String', required 'android.location.Location'

Hello I'm trying to send my location via SMS but keep getting this one error message which says:

Wrong 2nd argument type. Found: 'java.lang.String', required: 'android.location.Location'

Inspection info:

sendLocationSMS(String,android.location.Location)

in FullscreenActivity cannot be applied to (String,java.lang.String)

Here's the specific lines of code that I'm using:

private void sendLocationSMS(String phoneNumber, Location currentLocation) {
    SmsManager smsManager = SmsManager.getDefault();
    StringBuffer smsBody = new StringBuffer();
    smsBody.append("http://maps.google.com?q=");
    smsBody.append(currentLocation.getLatitude());
    smsBody.append(",");
    smsBody.append(currentLocation.getLongitude());
    smsManager.sendTextMessage(phoneNumber, null, smsBody.toString(), null, null);
}

In my onCreate I have this:

sendLocationSMS("MY PHONE NUMBER", "");

In sendLocationSMS("MY PHONE NUMBER", ""); second arg is a String, you should use a Location object. Try creating a new Location and put as second arg.

You are passing an empty String as a second argument while your method requires you to pass a parameter that is of type Location . Thus change sendLocationSMS("MY PHONE NUMBER", ""); to pass a variable of type Location in the second parameter. Try this on your onCreate
I noticed you didn't read about the ``Location``` class, so read it here

String provider = ""; // change this to your provider
Location currentLocation = new Location(provider);
sendLocationSMS("MY PHONE NUMBER", currentLocation);

As the answers say, this is clear argument type mismatch. Find here how to get the current location. If you do not want to pass the actual location data, just create a new Location object and pass it to the method call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM