美文网首页
android.view.InflateException: B

android.view.InflateException: B

作者: 寒冬_腊月 | 来源:发表于2021-01-27 16:28 被阅读0次

    背景

    测试发现个bug, 在华为mate9使用app会报错,其它手机是正常的

    具体报错信息如下

        java.lang.RuntimeException: Unable to start activity ComponentInfo{packname/activity path}: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
            at android.app.ActivityThread.startActivityNow(ActivityThread.java:3217)
            at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:139)
            at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:366)
            at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:779)
            at android.widget.TabHost.setCurrentTab(TabHost.java:433)
            at packname.ui.PatientDynamicMessageActivity.onClick(PatientDynamicMessageActivity.kt:134)
            at android.view.View.performClick(View.java:6659)
            at android.view.View.performClickInternal(View.java:6631)
            at android.view.View.access$3100(View.java:790)
            at android.view.View$PerformClick.run(View.java:26187)
            at android.os.Handler.handleCallback(Handler.java:907)
            at android.os.Handler.dispatchMessage(Handler.java:105)
            at android.os.Looper.loop(Looper.java:216)
            at android.app.ActivityThread.main(ActivityThread.java:7625)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
    

    解决

    这个问题是由于使用了activitygroup造成的,之前一直以为是activitygroup兼容性问题,后面才发面子activity调用了setTheme引起的,大概结构如下:

    class PatientDynamicMessageActivity extends ActivityGroup{}
    
    class Activity1 extends Activity(){}
    
    class Activity2 extends SuperActivity(){
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setTheme();//调用这个还原主工程主题就可以解决
      }
    }
    
    class SuperActivity extends Activity(){
         protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
             setContentView(R.layout.test);
             setTheme(R.style.test);//就是这一行代码引起的
          }
    }
    

    相关文章

      网友评论

          本文标题:android.view.InflateException: B

          本文链接:https://www.haomeiwen.com/subject/aweazktx.html