静听关山闻一叫
2018-06-05 13:25
采纳率: 100%
浏览 1.3k

自定义ViewGroup,调试抛出Error inflating class,求构造函数以外的原因?

 照着https://blog.csdn.net/lmj623565791/article/details/43131133这个网址想实现一个圆形旋转菜单,调试时发现在主页面的setContentView一步抛出 Error inflating class......异常,即自己的自定义ViewGroup无法被初始化,度娘说是构造函数的原因,但我确实把所有能找到的不同参数情况都加上去了,经测也不是未引用完整包名的原因;请问诸位,还可能是什么原因?
    先抛异常:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asus.newsapplication/com.example.asus.newsapplication.MainPage}: android.view.InflateException: Binary XML file line #12: Error inflating class com.example.asus.newsapplication.CircleMenuLayout
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                  at android.app.ActivityThread.access$800(ActivityThread.java:151)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5254)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
               Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.example.asus.newsapplication.CircleMenuLayout
                  at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                  at com.example.asus.newsapplication.MainPage.onCreate(MainPage.java:16)
                  at android.app.Activity.performCreate(Activity.java:5990)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                  at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:135) 
                  at android.app.ActivityThread.main(ActivityThread.java:5254) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:372) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
               Caused by: java.lang.InstantiationException: Can't instantiate abstract class com.example.asus.newsapplication.CircleMenuLayout
                  at java.lang.reflect.Constructor.newInstance(Native Method)
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:607)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                  at com.example.asus.newsapplication.MainPage.onCreate(MainPage.java:16) 
                  at android.app.Activity.performCreate(Activity.java:5990) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                  at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:135) 
                  at android.app.ActivityThread.main(ActivityThread.java:5254) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:372) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 

                                        再贴图片:
                                        ![图片说明](https://img-ask.csdn.net/upload/201806/05/1528204867_673557.png)
                                        ![图片说明](https://img-ask.csdn.net/upload/201806/05/1528204937_810371.png)
                                        ![图片说明](https://img-ask.csdn.net/upload/201806/05/1528204988_880336.png)
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 邪恶八进制 2018-06-06 01:01
    已采纳

    首先CircleMenuLayout这个类是不是一个抽象类?他是不能被设置为抽象类的

    打赏 评论
  • 邪恶八进制 2018-06-06 01:06

    首相类不能被实例化,你应该从这方面考虑一下滴

    打赏 评论
  • julychu23 2018-06-06 02:24

    初步推测原因:CircleMenuLayout是个抽象类。需要你贴出此类的全部定义。还有一种可能就是你的CircleMenuLayout的xml中存在错误。

    打赏 评论

相关推荐 更多相似问题