我正在嘗試使用Google Play服務獲取位置的小應用程序。事情是,我總是有這個錯誤,我不知道爲什麼。Android Studio不是抽象的並且不會覆蓋抽象方法
下面是代碼:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
//import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class Principal extends AppCompatActivity implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
gps = new MockLocationProvider(LocationManager.GPS_PROVIDER, Principal.this);
net = new MockLocationProvider(LocationManager.NETWORK_PROVIDER, Principal.this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
}
和錯誤是:
Error:(74, 8) error: Principal is not abstract and does not override abstract method onConnectionSuspended(int) in ConnectionCallbacks
如果我不實現ConnectionCallbacks
,OnConnectionFailedListener
,我有這樣的錯誤:
Error:(116, 41) error: incompatible types: Principal cannot be converted to ConnectionCallbacks
如果我刪除這個選項:
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
,不實現ConnectionCallbacks
,OnConnectionFailedListener
,我沒有錯誤,但GooglePlay Service
沒有連接。
我有這樣的搖籃:
compile 'com.google.android.gms:play-services-location:7.3.0'
我做錯了嗎?
謝謝大家。