墨客联盟

故天将降大任于斯人也...

《IllegalStateException异常》

一、开发背景

        使用butterknife:8.4.0 框架,用插件实现实例化控件。

二、异常日志


    java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.bql.vehiclemounteds/cn.bql.vehiclemounted.vehiclemounteds.activity.CarInspectionActivity}: java.lang.IllegalStateException: Required view 'content' with ID 2131689669 for field 'content' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3168)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3278)
       at android.app.ActivityThread.access$1000(ActivityThread.java:211)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6918)
       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:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
     Caused by: java.lang.IllegalStateException: Required view 'content' with ID 2131689669 for field 'content' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
       at butterknife.internal.Utils.findRequiredView(Utils.java:138)
       at butterknife.internal.Utils.findRequiredViewAsType(Utils.java:150)
       at cn.bql.vehiclemounted.vehiclemounteds.activity.CarInspectionActivity_ViewBinding.<init>(CarInspectionActivity_ViewBinding.java:30)
       at java.lang.reflect.Constructor.newInstance(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
       at butterknife.ButterKnife.bind(ButterKnife.java:124)
       at cn.bql.vehiclemounted.vehiclemounteds.activity.BaseActivity.onCreate(BaseActivity.java:32)
       at android.app.Activity.performCreate(Activity.java:6609)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3278)?
       at android.app.ActivityThread.access$1000(ActivityThread.java:211)?
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)?
       at android.os.Handler.dispatchMessage(Handler.java:102)?
       at android.os.Looper.loop(Looper.java:145)?
       at android.app.ActivityThread.main(ActivityThread.java:6918)?
       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:1404)?
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)?
     java.lang.IllegalStateException: Required view 'content' with ID 2131689669 for field 'content' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
       at butterknife.internal.Utils.findRequiredView(Utils.java:138)
       at butterknife.internal.Utils.findRequiredViewAsType(Utils.java:150)
       at cn.bql.vehiclemounted.vehiclemounteds.activity.CarInspectionActivity_ViewBinding.<init>(CarInspectionActivity_ViewBinding.java:30)
       at java.lang.reflect.Constructor.newInstance(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
       at butterknife.ButterKnife.bind(ButterKnife.java:124)
       at cn.bql.vehiclemounted.vehiclemounteds.activity.BaseActivity.onCreate(BaseActivity.java:32)
       at android.app.Activity.performCreate(Activity.java:6609)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3278)
       at android.app.ActivityThread.access$1000(ActivityThread.java:211)
       at an 


三、异常原因

        Activity里面加载了一个控件,但是XML里并没有这个控件。使用butterknife这个框架的时候,有时候会出现在这个Activity里面加载到另外一个布局的控件,然后你会莫名其妙的发现报错了,但是找到位置,对应的控件,戳进去之后是有xml对象的。再仔细看看,原来是Activity和对应的xml不一样。


四、异常处理

        找到相应的Activity,然后把多余的控件实例化代码删除即可。

        如上异常中CarInspectionActivity.class添加的content控件,CarInspectionActivity.class对应的XML布局里面并没有对应的控件,所以应该删除。



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/true_maitian/article/details/53991903
个人分类: 异常处理
上一篇《SpannableStringBuilder的使用》
下一篇《android stuido SVN(1)提交文件忽略》
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭