java - GoogleApiClient 是抽象的;无法实例化

标签 java android

这是我尝试实例化它的代码:

private synchronized void callConnection(){
    mGoogleApiClient = new GoogleApiClient().Builder
            .addOnConnectionFailedListener(this)
            .addConnectionCallbacks(this)
            .addApi(LocationServices.API)
            .build();
    mGoogleApiClient.connect();

这是我的 build.gradle 中的内容:

compile 'com.google.android.gms:play-services:6.5.87'

我收到此错误:

Error:(222, 28) error: GoogleApiClient is abstract; cannot be instantiated
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
 >Compilation failed; see the compiler error output for details.

最佳答案

这是一种构建器模式,因此您需要实例化 Builder (静态内部类)对象,该对象负责使用定义的操作(调用的方法)构造底层对象,因此请使用

new GoogleApiClient.Builder()

而不是

new GoogleApiClient().Builder

关于java - GoogleApiClient 是抽象的;无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46875431/

相关文章:

java - VLCJ RTP 流客户端

java - org.hibernate.MappingException : Could not determine type for:

java - 显示 DialogFragment 的应用程序在旋转后崩溃

java - 在 Android Studio 中按下时更改操作栏菜单项图标

java - 不在 html 文档中加载来自网络的图像?

java - 为什么原始包装类在作为参数传递后不会改变?

android - Android Gradle构建需要大量时间来执行代码

android - 在上滑面板中旋转 ImageView

android - 当我选择单选按钮时,它应该同时提交答案并打开下一个 Activity 。我怎样才能做到这一点?

java - 如何仅将来电铃声静音而不将短信静音