Java 与Google plus集成:初始化Google plus API客户端不起作用
我有一个主要的活动,我有一个按钮,意图谷歌加上活动 这是我在Java 与Google plus集成:初始化Google plus API客户端不起作用,java,android,google-plus,Java,Android,Google Plus,我有一个主要的活动,我有一个按钮,意图谷歌加上活动 这是我在onCreateView()之前的GooglePlus.java代码: my标签的logcat过滤器如下所示: 10-05 17:21:52.890: D/my(20539): intent started 10-05 17:21:52.910: D/my(20539): in oncreateview 10-05 17:21:52.920: D/my(20539): setcontentview is correct 10-05 17
onCreateView()之前的GooglePlus.java
代码:
my
标签的logcat过滤器如下所示:
10-05 17:21:52.890: D/my(20539): intent started
10-05 17:21:52.910: D/my(20539): in oncreateview
10-05 17:21:52.920: D/my(20539): setcontentview is correct
10-05 17:21:52.920: D/my(20539): layout mapped
10-05 17:21:52.920: D/my(20539): listeners are correct
因此,错误在于初始化google plus api客户端。我试了一个小时,但没发现问题所在
logcat原始错误日志为:
10-05 17:21:52.920: E/AndroidRuntime(20539): in writeCrashedAppName, pkgName :com.example.mapsdemo
10-05 17:21:52.920: E/AndroidRuntime(20539): FileNotFoundException while trying to write in crash app file
10-05 17:21:52.920: E/AndroidRuntime(20539): FATAL EXCEPTION: main
10-05 17:21:52.920: E/AndroidRuntime(20539): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapsdemo/com.example.mapsdemo.GooglePlus}: java.lang.NullPointerException: Null options are not permitted for this Api
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.os.Looper.loop(Looper.java:137)
10-05 17:21:52.920: E/AndroidRuntime(20539): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-05 17:21:52.920: E/AndroidRuntime(20539): at java.lang.reflect.Method.invokeNative(Native Method)
10-05 17:21:52.920: E/AndroidRuntime(20539): at java.lang.reflect.Method.invoke(Method.java:511)
10-05 17:21:52.920: E/AndroidRuntime(20539): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
10-05 17:21:52.920: E/AndroidRuntime(20539): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
10-05 17:21:52.920: E/AndroidRuntime(20539): at dalvik.system.NativeStart.main(Native Method)
这是清单代码:
<permission
android:name="com.example.mapsdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapsdemo.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name" >
</activity>
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name=".GooglePlus"
android:label="@string/title_activity_google_plus" >
</activity>
</application>
我遗漏了什么吗?plz帮助。最后我解决了错误:
出现此错误是因为Google plus API不允许使用空选项
将addApi(Plus.API,null)
更正为addApi(Plus.API)
因此,最后要做以下工作:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
Log.d("my", " Initialized google plus api client");
}
最后我解决了这个错误:
出现此错误是因为Google plus API不允许使用空选项
将addApi(Plus.API,null)
更正为addApi(Plus.API)
因此,最后要做以下工作:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
Log.d("my", " Initialized google plus api client");
}
.addApi(Plus.API,Plus.PlusOptions.builder().build()).addApi(Plus.API,Plus.PlusOptions.builder().build())您的权限(清单文件)怎么样?它们好吗?@alpinescrambler添加了清单您的权限(清单文件)怎么样?它们好吗?@alpinescrambler添加了清单