1

我在android studio中有这样的代码:

@Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (amapLocation != null && amapLocation.getAMapException() != null
                && amapLocation.getAMapException().getErrorCode() == 0) {
            // get location information
            mLocation = amapLocation;
            MyApp.getInstance().getPrefs().Latitude()
                    .put("" + amapLocation.getLatitude());
            MyApp.getInstance().getPrefs().Longitude()
                    .put("" + amapLocation.getLongitude());
        }

    }

getAMapException 方法返回从 Exception 扩展的 AMapLocException 实例。

现在 android studio 显示了一些提示,我不知道如何处理它们。 在此处输入图像描述

报告对忽略调用结果并返回 Throwable类型(或子类型)的对象的特定方法的调用。通常这些类型的方法被用作异常的工厂方法,并且应该抛出结果。

而且我还通过google找到了ThrowableResultOfMethodCallIgnored.java文件源,但我仍然不知道如何处理它。

4

1 回答 1

2

这只是一个警告,您调用了一个返回 Throwable 的方法,但实际上并没有抛出它。

一种解决方案是执行以下操作

Throwable t = amapLocation.getAMapException();
if (t != null) {
    throw t;
}

当然,您不必抛出异常。您可以选择忽略或在条件中使用它。

于 2015-12-31T16:11:02.860 回答