zoukankan      html  css  js  c++  java
  • Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述

    FATAL EXCEPTION: main
    Process: com.whereru.greengrass.goforit, PID: 13847
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whereru.greengrass.goforit/com.whereru.greengrass.goforit.activity.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.whereru.greengrass.goforit.ui.BaseViewPager
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2457)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
    at android.app.ActivityThread.access$1200(ActivityThread.java:165)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5669)
    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:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.whereru.greengrass.goforit.ui.BaseViewPager
    at android.view.LayoutInflater.createView(LayoutInflater.java:635)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:825)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:935)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:523)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:368)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:380)
    at android.app.Activity.setContentView(Activity.java:2188)
    at com.whereru.greengrass.goforit.activity.MainActivity.onCreate(MainActivity.java:24)
    at android.app.Activity.performCreate(Activity.java:6102)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2410)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) 
    at android.app.ActivityThread.access$1200(ActivityThread.java:165) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5669) 
    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:960) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
    Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
    at java.lang.Class.getConstructor(Class.java:531)
    at java.lang.Class.getConstructor(Class.java:495)
    at android.view.LayoutInflater.createView(LayoutInflater.java:599)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:825) 
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:935) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:523) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:425) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:368) 
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:380) 
    at android.app.Activity.setContentView(Activity.java:2188) 
    at com.whereru.greengrass.goforit.activity.MainActivity.onCreate(MainActivity.java:24) 
    at android.app.Activity.performCreate(Activity.java:6102) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2410) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) 
    at android.app.ActivityThread.access$1200(ActivityThread.java:165) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5669) 
    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:960) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

    2. 自定义View时,要同时覆写

     public XXXX(Context context) {
            super(context);
        }
    
        /**
         * 自定义View时,如果自定义View有属性,这个方法一定要覆写!!
         *
         * @param context
         * @param attrs
         */
        public XXXX(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
  • 相关阅读:
    Apache Solr 远程命令+XXE执行漏洞(CVE-2017-12629)
    Apache Shiro RememberMe 1.2.4 反序列化漏洞
    ActiveMQ任意文件写入漏洞(CVE-2016-3088)
    ssrf对redis未授权访问写webshell
    fastjson<1.2.47 RCE 漏洞复现
    Redis基于主从复制的RCE(redis4.x 5.x)复现
    本机浏览器无法访问linux的tomcat
    测试覆盖率工具EclEmma安装与使用
    eclemma怎么安装 eclemma的安装与简单使用图文教程(附下载)
    .bat脚本基本命令语法
  • 原文地址:https://www.cnblogs.com/LuLei1990/p/5511501.html
Copyright © 2011-2022 走看看