【发布时间】:2016-09-26 19:47:24
【问题描述】:
尝试在 Nexus 5 模拟器(API 24 / Google API)上运行我的代码(如下)时出现上述异常...
E/ACRA: ACRA caught a RuntimeException for com.example
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.SplashActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:414)
at com.android.internal.app.AlertController.installContent(AlertController.java:236)
at android.app.AlertDialog.onCreate(AlertDialog.java:423)
at android.app.Dialog.dispatchOnCreate(Dialog.java:389)
at android.app.Dialog.show(Dialog.java:293)
at com.example.SplashActivity.checkPlayServices(SplashActivity.java:195)
at com.example.SplashActivity.onCreate(SplashActivity.java:74)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:528)
at android.widget.TextView.<init>(TextView.java:783)
at android.widget.TextView.<init>(TextView.java:704)
at android.widget.TextView.<init>(TextView.java:700)
E/ACRA: at com.android.internal.widget.DialogTitle.<init>(DialogTitle.java:41)
... 34 more
我看到了类似问题的答案,建议将 SplashActivity.this 传递给 Dialog 构造函数,而不是传递 getApplicationContext() - 但我已经传递了一个活动实例。
有什么想法可能是错的吗?
我的代码!...
private boolean checkPlayServices() {
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(this);
if (result != ConnectionResult.SUCCESS) {
if (googleAPI.isUserResolvableError(result)) {
Dialog dialog = googleAPI.getErrorDialog(this, result, PLAY_SERVICES_RESOLUTION_REQUEST);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
SplashActivity.this.finish();
}
});
dialog.show();
}
return false;
}
return true;
}
【问题讨论】:
-
您的 xml 布局不支持某些内容。
-
发布您的 xml 布局。问题是膨胀 com.android.internal.widget.DialogTitle
-
我现在已经添加了我的代码。如您所见,我收到了来自
GoogleApiAvailability的错误对话框,所以我对布局文件没有发言权...
标签: android google-play-services android-dialog