使用chrisjenx书法布局充气器时发生充气异常,android.view.InflateException



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

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)

我检查了一些答案,但看不到有人在文本视图方面遇到问题。

在我的活动中,我对书法的依恋如下

@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>

我注意到工作室对android发出警告:colorAccent,并替换为"colorAccent",删除了警告,但崩溃仍然存在。有线索表明我做错了什么吗??

终于解决了问题,因为问题是根据崩溃日志在Textview中发生的

由以下原因引起:android.view.InflateException:二进制XML文件行#13:膨胀类TextView 时出错

TLDR:不要为TextView使用setbackground,因为它很容易出错(三星),特别是如果它的Vector可绘制

我通过删除文本视图验证了崩溃停止了。问题是我曾经为我的文本视图设置背景图像,它是一个SVG图像,我一直使用appCompact库(v23)。只有通过"app:srcCompat"或"setImageResource()"才支持设置矢量可绘制,这是使用矢量可绘制的万无一失的方法。

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

我从textview中删除了Vector drawable,并在textview下方添加了另一个Imageview,使用"src:compact"绘制Vector dravable,这样在视觉上它们看起来仍然相同,即带有背景的Text视图。

如果应用程序大小不是问题,你也可以使用png/jpg资源,避免在布局中创建额外的图像视图。

适用于Android Studio 3.0.1

我遇到了同样的问题,我最终解决了打开gradle.properties并添加了以下行:

android.enableAapt2=false

相关内容

  • 没有找到相关文章

最新更新