getString()中出现错误

洛克希·潘迪(Lokesh Pandey)

我是android新手,正在编写一个应用程序以基于纬度和经度获取地址。在FetchAddressIntentService类中,在将字符串添加到string.xml文件后getString()函数中出现一个错误,指出该方法getString(int)未定义,这是我遇到的一个错误我遇到的下一个错误是在此行上Geocoder geocoder = new Geocoder(this,Locale.getDefault());说该类的构造函数地址解析器未定义。这是FetchAddressIntentService类代码:

    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Locale;
    import android.content.Intent;
    import android.location.Address;
    import android.location.Geocoder;
    import android.location.Location;
    import android.os.Bundle;
    import android.os.ResultReceiver;
    import android.text.TextUtils;
    import android.util.Log;
    public class FetchAddressIntentService {

        private static final String TAG = null;
        protected ResultReceiver mReceiver;

        protected void onHandleIntent(Intent intent){
           Geocoder geocoder = new Geocoder(this,Locale.getDefault());
           String errorMessage = "";

            // Get the location passed to this service through an extra.
            Location location = intent.getParcelableExtra(
                    Constants.LOCATION_DATA_EXTRA);
            List<Address> addresses = null;

            try {
                addresses = geocoder.getFromLocation(
                        location.getLatitude(),
                        location.getLongitude(),
                        // In this sample, get just a single address.
                        1);
            } catch (IOException ioException){
                // Catch network or other I/O problems.
                errorMessage = getString(R.string.service_not_available);
                Log.e(TAG, errorMessage, ioException);
            } catch (IllegalArgumentException illegalArgumentException) {
                // Catch invalid latitude or longitude values.
                errorMessage = getString(R.string.invalid_lat_long_used);
                Log.e(TAG, errorMessage + ". " +
                        "Latitude = " + location.getLatitude() +
                        ", Longitude = " +
                        location.getLongitude(), illegalArgumentException);
            }

            // Handle case where no address was found.
            if (addresses == null || addresses.size()  == 0) {
                if (errorMessage.isEmpty()) {
                    errorMessage = getString(R.string.no_address_found);
                    Log.e(TAG, errorMessage);
                }
                deliverResultToReceiver(Constants.FAILURE_RESULT, errorMessage);
            } else {
                Address address = addresses.get(0);
                ArrayList<String> addressFragments = new ArrayList<String>();

                // Fetch the address lines using getAddressLine,
                // join them, and send them to the thread.
                for(int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                    addressFragments.add(address.getAddressLine(i));
                }
                Log.i(TAG, getString(R.string.address_found));
                deliverResultToReceiver(Constants.SUCCESS_RESULT,
                        TextUtils.join(System.getProperty("line.separator"),
                                addressFragments));
            }

        }
        private void deliverResultToReceiver(int resultCode, String message) {
            Bundle bundle = new Bundle();
            bundle.putString(Constants.RESULT_DATA_KEY, message);
            mReceiver.send(resultCode, bundle);
        }
}

有帮助吗?先感谢您。

Gueorgui Obregon

您忘记了从扩展FetchAddressIntentService课程IntentService只需添加:

public class FetchAddressIntentService extends IntentService {
...

希望能有所帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

烧瓶中出现奇怪的错误:

来自分类Dev

程序中出现错误流浪“#”

来自分类Dev

在if语句中出现错误

来自分类Dev

通道中出现CoroutineContext错误

来自分类Dev

烧瓶中出现奇怪的错误:

来自分类Dev

程序中出现错误流浪“#”

来自分类Dev

在Viewbag列表中出现错误

来自分类Dev

SVN更新中出现错误

来自分类Dev

CakePHP在错误日志中出现空错误

来自分类Dev

Apache错误日志中出现错误

来自分类Dev

错误:程序中出现流浪“ \ 240”

来自分类Dev

为什么在MongoDB中出现UserNotFound错误?

来自分类Dev

教程中出现多个SparkContexts错误

来自分类Dev

Atom中出现“ CERT_UNTRUSTED”错误

来自分类Dev

TabPagerIndicator在导航抽屉中出现错误

来自分类Dev

在HAPI服务器中出现错误

来自分类Dev

在语法中出现移位/减少错误

来自分类Dev

Spring MVC中出现400错误

来自分类Dev

在我的PHP / SQL脚本中出现错误?

来自分类Dev

Powershell中出现意外的令牌错误

来自分类Dev

在类似查询中出现错误“参数太少”

来自分类Dev

通话中出现额外参数“动画”-错误

来自分类Dev

减少在大型系统中出现错误的机会

来自分类Dev

在moment.js中出现错误的月份

来自分类Dev

Rails:动作中出现双重渲染错误

来自分类Dev

Java中出现“无法解决扫描”错误

来自分类Dev

错误:程序中出现流浪“ \ 226”

来自分类Dev

JavaScript中出现“预期的':'”错误的未知原因

来自分类Dev

Apache Tomcat中出现奇怪的错误?