日月同辉山川同在
2021-04-20 20:59
采纳率: 25%
浏览 33

Android中的神奇问题RuntimeException

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.smartcity, PID: 6399
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smartcity/com.example.smartcity.ui.home.News}: android.view.InflateException: Binary XML file line #49: Binary XML file line #49: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.view.InflateException: Binary XML file line #49: Binary XML file line #49: Error inflating class <unknown>
     Caused by: android.view.InflateException: Binary XML file line #49: Error inflating class <unknown>
     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 com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        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.rInflate(LayoutInflater.java:861)
        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.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.smartcity.ui.home.News.onCreate(News.java:25)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.smartcity:drawable/newsbackground with resource ID #0x7f0700bb
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/newsbackground.xml from drawable resource ID #0x7f0700bb
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
        at android.content.res.Resources.loadDrawable(Resources.java:858)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
        at android.view.View.<init>(View.java:4202)
        at android.view.ViewGroup.<init>(ViewGroup.java:579)
        at android.widget.LinearLayout.<init>(LinearLayout.java:211)
        at android.widget.LinearLayout.<init>(LinearLayout.java:207)
        at android.widget.LinearLayout.<init>(LinearLayout.java:203)
        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 com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
        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.rInflate(LayoutInflater.java:861)
        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.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.smartcity.ui.home.News.onCreate(News.java:25)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4<gradient> tag requires 'angle' attribute to be a multiple of 45
        at android.graphics.drawable.GradientDrawable.updateGradientDrawableGradient(GradientDrawable.java:1572)
        at android.graphics.drawable.GradientDrawable.inflateChildElements(GradientDrawable.java:1394)
        at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:1215)
        at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
            ... 41 more
 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 陈蒙_ 2021-04-22 20:59
    已采纳

    安卓的 xml 文件布局优点是声明式编程、可视化等,缺点就是编译检查太弱,太容易出现 InflateException。

    一般这种 InflateException 错误都是 xml 文件中的某个控件的路径、属性错误导致的,当然也不排除一些匪夷所思问题比如:https://blog.csdn.net/zhaizu/article/details/106380880?spm=1001.2014.3001.5501

    建议按照报错堆栈的提示,看下 xml 文件第 49 行的代码,是否存在明显导致控件解析失败的问题。

    点赞 评论
  • 代码的灵魂是bug! 2021-04-21 09:17

    xml 文件解析错误:res/drawable/newsbackground.xml

    点赞 1 评论

相关推荐 更多相似问题