【问题标题】:Google Plus Android SDK: Error inflating class com.google.android.gms.plus.PlusOneButtonGoogle Plus Android SDK:膨胀类 com.google.android.gms.plus.PlusOneButton 时出错
【发布时间】:2013-12-06 09:32:34
【问题描述】:

我在我的 Android 应用中使用 Google Plus SDK。在一些罕见的设备上,当包含 Google Plus 按钮的视图被夸大时,我遇到了以下崩溃:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); // CRASH HERE

....
}

我的 GooglePlus 按钮在 xml 中是这样的:

<com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
....
/>


<com.google.android.gms.plus.PlusOneButton
  xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
  android:id="@+id/plus_one_button"
  ...
   />

在日志下方。关于解决这个问题的方法有什么想法吗?

谢谢!!

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.audioguidia.myweather/com.audioguidia.myweather.MyWeatherActivity}: android.view.InflateException: Binary XML file line #111: Error inflating class com.google.android.gms.plus.PlusOneButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #111: Error inflating class com.google.android.gms.plus.PlusOneButton
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.audioguidia.myweather.MyWeatherActivity.onCreate(MyWeatherActivity.java:419)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 22 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1013)
at android.content.res.Resources.getDrawable(Resources.java:658)
at com.google.android.gms.plus.PlusOneDummyView$b.getDrawable(Unknown Source)
at com.google.android.gms.plus.PlusOneDummyView.<init>(Unknown Source)
at com.google.android.gms.internal.bu.a(Unknown Source)
at com.google.android.gms.plus.PlusOneButton.d(Unknown Source)
at com.google.android.gms.plus.PlusOneButton.<init>(Unknown Source)
... 25 more

我遇到问题的设备示例(仅在每种类型的少数设备上发生,否则我会收到更多崩溃报告):

  • crane-a702jhorang
  • MW0712
  • 平板电脑 S (nbx03)
  • 列表项
  • 银河 Y (GT-S5360B)
  • 银河 Y 双人组 (GT-S6102)
  • rk2928sdk
  • rk2928sdk
  • rk2928sdk
  • Galaxy Note II(t03g)
  • 银河迷你 (GT-S5570I)
  • e1901_v77_jdt1_9p017_fwvga
  • Nexus S (crespo)
  • 银河王牌 (GT-S5830i)
  • 起重机网
  • ITP-R208W (rk30sdk)

【问题讨论】:

  • 由于您说并非所有设备都会发生这种情况,您能否编辑您的问题并提供您遇到问题的设备类型?
  • 完成!感谢您的帮助。
  • @Regis_AG 我们也看到了很多这样的问题,你找到解决方案了吗?
  • 不,没有找到问题的根源。有人解决了吗?谢谢。

标签: android eclipse google-plus google-play-services google-plus-one


【解决方案1】:

我收到了来自 rk2928sdk 的 ACRA 报告,但有同样的例外。幸运的是,我将来自GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) 的信息存储在报告中。此调用返回SERVICE_INVALID

我在一个非常基本的“关于”活动中使用PlusOneButton,因此我决定复制此活动并从第二个布局中删除PlusOneButton。现在我正在捕捉InflateException,如果捕捉到异常,则使用不带按钮的布局。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView;
    try {
        rootView = inflater.inflate(R.layout.activity_about, container, false);
    } catch (InflateException e) {
        rootView = inflater.inflate(R.layout.activity_about_fallback, container, false);
    }
    return rootView;
}

try-catch 可以替换为检查 .isGooglePlayServicesAvailable() 是否返回正常值。但我不知道哪些返回值可以保证PlusOneButton 的可用性,所以我将其留给丑陋的try-catch

【讨论】:

  • 是否可以只使用普通 CTOR 而不是充气?你认为它有帮助吗?另外,如何向 Google 报告此问题?普通网站仅适用于 Android 代码,而不适用于 Google 服务...
【解决方案2】:

只需将plus 播放服务添加到您的应用:

    compile 'com.google.android.gms:play-services-plus:10.0.1' 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多