com.google.android.gms.common.api.GoogleAppClient$ConnectionCallbacks中出现错误

com.google.android.gms.common.api.GoogleAppClient$ConnectionCallbacks中出现错误,android,google-maps,Android,Google Maps,我是Android新手,目前我正在制作一个非常基本的谷歌地图。并且得到了这个错误。 谁能帮我一下吗 这是logcat中的错误 `07-02 10:49:20.882 25215-25215/com.example.prashant.nuhani_go E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.prashant.nuhani_go, PID: 25215 java.lang.RuntimeE

我是Android新手,目前我正在制作一个非常基本的谷歌地图。并且得到了这个错误。 谁能帮我一下吗

这是logcat中的错误

`07-02 10:49:20.882  25215-25215/com.example.prashant.nuhani_go      E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.prashant.nuhani_go, PID: 25215
    java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.example.prashant.nuhani_go/com.example.prashant.nuhani_go.seco ndLocationChoosen}:     java.lang.ClassCastException:  com.example.prashant.nuhani_go.secondLocationChoosen cannot be cast to   com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks
            at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.ClassCastException:     com.example.prashant.nuhani_go.secondLocationChoosen cannot be cast to com.google.android.gms.common.api.GoogleApiClient$ConnectionCallbacks
        at com.example.prashant.nuhani_go.secondLocationChoosen.onCreate(secondLocationChoosen.java:46)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278).....

我的java文件:

      package com.example.prashant.nuhani_go;
      import android.support.v7.app.ActionBarActivity;
      import android.os.Bundle;
      import android.view.Menu;
      import android.view.MenuItem;
      import android.view.View;
      import android.widget.AutoCompleteTextView;
      import android.widget.Button;
      import android.widget.EditText;
      import com.google.android.gms.common.ConnectionResult;
      import com.google.android.gms.common.api.GoogleApiClient;
      import    com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
      import com.google.android.gms.location.places.Places;


     public class secondLocationChoosen extends ActionBarActivity {
private GoogleApiClient mGoogleApiClient;
private AutoCompleteTextView mAutocompleteView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second_location_choosen);

  // Checking the destination and starting location, they shouldn't be empty
   final EditText editText3 =(EditText)findViewById(R.id.editText3);
   final EditText editText4 =(EditText)findViewById(R.id.editText4);
        Button button2 = (Button)findViewById(R.id.button2);
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if( editText3.getText().toString().length() == 0 )
                editText3.setError( "This field cannot be empty !" );
            if( editText4.getText().toString().length() == 0 )
                editText4.setError( "This field cannot be empty !" );
        }
    });


    // Construct a GoogleApiClient for the {@link Places#GEO_DATA_API} using AutoManage
    // functionality, which automatically sets up the API client to handle Activity lifecycle
    // events. If your activity does not extend FragmentActivity, make sure to call connect()
    // and disconnect() explicitly.
    mGoogleApiClient = new GoogleApiClient
            .Builder(this)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addConnectionCallbacks((ConnectionCallbacks) this)
            .addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener) this)
            .build();


    // Retrieve the AutoCompleteTextView that will display Place suggestions.
    //mAutocompleteView = (AutoCompleteTextView)
    //        findViewById(R.id.place);
    // Register a listener that receives callbacks when a suggestion has been selected
    //mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_second_location_choosen, menu);
    return true;
}

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

@Override
protected void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

我已经启用了GoogleMapsAPI,并且在清单文件中添加了我的密钥

删除GoogleAppClient实例化中的强制转换,并在类中实现方法

尝试在类中实现这些接口,您会发现缺少了什么。Android Studio将向您抛出几个“不实现x方法”警告


您告诉ApiClient类的“this”当前实例实现了这两个接口,但实际上并没有实现它们。因此,ClassCastException。

使您的活动实现GoogleAppClient.ConnectionCallbacksGoogleAppClient.OnConnectionFailedListener