【问题标题】:GCM class cast exceptionGCM 类转换异常
【发布时间】:2015-04-25 04:59:02
【问题描述】:
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
        GooglePlayServicesUtil.getErrorDialog(resultCode, (Activity)  
     context, PLAY_SERVICES_RESOLUTION_REQUEST).show();
    } 

例外:

java.lang.ClassCastException: com.interconnect.garhoud.Garhoud 无法转换为 android.app.Activity 在 com.interconnect.library.gcm.Util.checkPlayServices(Util.java:96) 在 com.interconnect.library.gcm.Regiseter.handleRegister(Regiseter.java:53) 在 com.interconnect.library.gcm.Regiseter.onHandleIntent(Regiseter.java:30) 在 android.app.IntentService$ServiceHandler.handleMessage
(IntentService.java:65) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:146) 在 android.os.HandlerThread.run(HandlerThread.java:61)

我使用上下文作为 getApplicationContext,因为我已经从意图服务调用了它。我该如何处理这个异常?

【问题讨论】:

  • 很棒的资源,由开发人员提供给完全基于 ClassCastException 的开发人员。 github.com/mopub/mopub-android-sdk/issues/13.
  • 查看错误日志并看到它说您无法投射到 Activity 并且仍然将其投射到 Activity
  • 我没有要在该方法中使用的活动实例,因为我从一个从 IntentService 扩展的类中调用它,它适用于大多数设备,但最近我在结构中发现了这个错误

标签: java android google-cloud-messaging


【解决方案1】:

由于您无法显示来自服务的对话框,因此您可以改用 GooglePlaySErvicesUtil.showErrorNotification(),它允许您发布通知,提示用户使用 Google Play 服务解决错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多