2016-09-26 3 views
1

Nexus 5エミュレータ(API 24/Google API)でコードを実行しようとすると、上記の例外が発生します...Android - java.lang.reflect.InvocationTargetExceptionを呼び出すdialog.show()

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 

は、私はむしろgetApplicationContext()を渡すよりも、ダイアログのコンストラクタにSplashActivity.thisを渡すことをお勧め類似した質問の回答を見て - しかし、私はすでに活動のインスタンスを渡しています。

何が間違っている可能性がありますか?

私のコード!...ダウン以下

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; 
} 
+0

xmlレイアウトでは何かがサポートされていません。 – njzk2

+0

あなたのXMLレイアウトを投稿してください。問題は、com.android.internal.widget.DialogTitleを膨らませることです。 –

+0

私のコードを今追加しました。ご覧のとおり、「GoogleApiAvailability」からエラーダイアログが表示されるので、レイアウトファイルについては何も言わないでください。 –

答えて

0

エラー方法は

java.lang.UnsupportedOperationException: 
    Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1} 

を説明しますと、これはColorStateListは、ターゲット・デバイス上で評価することを試みている間に発生するようです。したがって、アプリケーションのminSdkと矛盾するXML属性がある場合は、色の定義を確認します。一般的には、Lintを実行すると、直接このようなエラーが発生する可能性があります。コマンドラインで./gradlew lintを使用すると非常にうまくいきます。

+0

ありがとうございました。色の定義をチェックする方法や、 './gradlew lint'をどこで使うのかについて私は少し慣れていますか? (NB - 私のアプリのminSdkVersionは15です。) –

+0

Androidスタジオの下段の引き出しにある「端末」ウィンドウを開きます。 Windowsでは、 'gradlew.bat lint'と入力して実行する必要があります。macOSとLinuxでは' ./gradlew lint'コマンドです。 –

+0

ターミナルで 'gradlew.bat lint'を実行しましたが、twitter4jの依存関係に関する3つのエラーが出たので、私はそのプロジェクトから削除しましたが、私はまだ同じ例外を受けています。しかし、私はこの警告に気づきました: 'W/GooglePlayServicesUtil:古いGoogle Playサービス。基本的な問題であるかもしれない9683000が必要ですが、9452480'が見つかりましたか? –

0

Thomas Kellerのコメントhis answerのおかげで解決策が見つかりました。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:alertDialogTheme">@style/MyAlertDialog</item> 
    <item name="alertDialogTheme">@style/MyAlertDialog</item> 
</style> 

<style name="MyAlertDialog" parent="Theme.AppCompat.Dialog.Alert"> 
    <item name="colorAccent">?attr/colorAccent</item> 
</style> 

のGoogle APIのダイアログは、このスタイルを使用しようとしていたので、私のxmlからそれを削除すると問題を修正しました:

基本的に、私は私のv21\style.xmlファイルに自分のダイアログのスタイルを使用していました。

しかし、私はまだMyAlertDialog(そのcolorAccentの値)を使用したいと思いますので、誰かがGoogle APIダイアログ(およびその他のGoogle /システムダイアログ)を和らげるためにどの色を追加する必要があるかを知っていますか?

関連する問題