ButterKnife java.lang.ClassCastException: android.view.View cannot be cast to android.app.Activity

今天使用ButterKnife报以下错误:

                                        Caused by: java.lang.ClassCastException: android.view.View cannot be cast to android.app.Activity
                                                                   at butterknife.internal.Finder$2.getContext(Finder.java:35)
                                                                   at butterknife.internal.Finder.getResourceEntryName(Finder.java:111)
                                                                   at butterknife.internal.Finder.castView(Finder.java:82)
                                                                   at hibaby.expert.course.live.LiveActivity_ViewBinding.(LiveActivity_ViewBinding.java:32)
                                                                   at hibaby.expert.course.live.LiveActivity_ViewBinder.bind(LiveActivity_ViewBinder.java:13)
                                                                   at hibaby.expert.course.live.LiveActivity_ViewBinder.bind(LiveActivity_ViewBinder.java:10)
                                                                   at butterknife.ButterKnife.bind(ButterKnife.java:125)
                                                                   at hibaby.expert.course.live.LiveActivity.onCreate(LiveActivity.java:67)
                                                                   at android.app.Activity.performCreate(Activity.java:6161)
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)

经过检查,发现,并非是ButterKnife.bind(Activity)错误,而是声明的对象中,有一个View类型的视图,被声明成了TextView而导致的错误。ButterKnife不能正确打印此错误,不知道算不算他们的BUG。


    //更正前
    @BindView(R.id.v_left)
    TextView tvLeft;
    //更正后
    @BindView(R.id.v_left)
    View tvLeft;

OK,问题解决。

你可能感兴趣的:(个人)