这是我尝试实例化它的代码:
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/