使用chrisjenx CalligraphyLayoutInflater时出现InflateException,android.view.InflateException [英] InflateException when using chrisjenx CalligraphyLayoutInflater , android.view.InflateException

查看:161
本文介绍了使用chrisjenx CalligraphyLayoutInflater时出现InflateException,android.view.InflateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在我们的项目中,我们使用书法库,它没有任何问题,但是现在在我添加的一项活动中,它随着以下堆栈跟踪而不断崩溃:

Hi So in our project we are using calligraphy library , it works with no issues but now in one of the activity i added it keeps crashing with the following stacktrace:

01-23 02:25:32.178 3654-3654/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 3654
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.activities.MultipleActivity}: android.view.InflateException: Binary XML file line #98: Error inflating class com.example.components.WLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #98: Error inflating class com.example.components.WLayout
    at android.view.LayoutInflater.createView(LayoutInflater.java:621)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.example.activities.MultipleActivity.onCreate(MultipleActivity.java:62)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
    at android.app.ActivityThread.access$800(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5017) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:595)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211) 
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20) 
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.example.activities.MultipleActivity.onCreate(MultipleActivity.java:62) 
    at android.app.Activity.performCreate(Activity.java:5231) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
    at android.app.ActivityThread.access$800(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5017) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class TextView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:840)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)

我检查了一些答案,但看不到有人遇到textview问题.

I checked a few answers but cant see anyone facing issue with textview.

我在活动中对书法的重视程度如下

I am attaching to calligraphy as follows in my activity

@Override
protected void attachBaseContext(Context newBase) {
  super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

活动主题如下

    <style name="AppTheme.Compat.ActionBar.Dark.NoBackground" parent="AppTheme.Compat.ActionBar.Dark">
        <item name="android:windowBackground">@null</item>
        <item name="android:textColor">@color/alert_title</item>
        <item name="android:textColorPrimary">@color/gray400</item>
        <item name="android:colorAccent">@color/alert_button</item>
    </style>

我注意到studio对android:colorAccent发出警告,并替换为"colorAccent",删除了警告,但崩溃仍然存在.任何线索我在这里做错了什么??

I noticed studio giving warning for android:colorAccent and replace with "colorAccent" that removed the warning but the crash remained . Any clues what am I doing wrong here ??

推荐答案

最后确定了问题,因为根据崩溃日志,问题是在Textview中发生的

Finally figured out the problem , Since the issue was happening in Textview as per the crash logs

原因:android.view.InflateException:二进制XML文件第13行:膨胀类TextView时出错

Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class TextView

TLDR:不要将setbackground用于容易发生bug的TextView(三星),尤其是其Vector可绘制的情况下.

我通过删除textview验证了崩溃停止发生的问题.问题是我曾经为我的textview设置背景图像,这是一个SVG图像,并且我已经使用了appCompact库(v23).仅通过"app:srcCompat"或"setImageResource()"支持设置矢量可绘制,这是使用矢量可绘制的万无一失的方法.

I verified by removing the textview the crash stopped happening.The issue was i used to set background image for my textview and it was a SVG image and i have been appCompact library(v23). Setting vector drawable is only supported via "app:srcCompat" or "setImageResource()" as the foolproof way to use vector drawable.

我阅读了此博客文章,以查看 https ://android-developers.googleblog.com/2016/02/android-support-library-232.html 我看到以前支持的Textview已被删除,这意味着它不稳定且容易出错.

I read the this blog post to see https://android-developers.googleblog.com/2016/02/android-support-library-232.html I see previous supported Textview has now been striked out , which means its not stable and bug prone.

我从textview中移除了Vector可绘制对象,并在紧靠textview下方的位置添加了另一个Imageview,并使用"src:compact"绘制了矢量可绘制对象,因此在视觉上它们看起来仍然相同,即具有背景的Text视图.

I removed the Vector drawable from textview and added a another Imageview just below textview with the vector drawable using "src:compact", so that visually they still look same i.e a Text view with background.

如果应用大小不成问题,您还可以使用png/jpg资源,并避免在布局中创建额外的imageview.

If app size isnt a issue you can also use a png /jpg resource and avoid the creation of extra imageview in your layout.

这篇关于使用chrisjenx CalligraphyLayoutInflater时出现InflateException,android.view.InflateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆