android - ButterKnife使用异常
PHP中文网
PHP中文网 2017-04-17 16:14:12
0
3
388

ButterKnife使用异常

异常信息

Error:(23, 81) 错误: @Bind fields must extend from View or be an interface. (...DemoActivity.mRecycler)

代码

    @Bind(R.id....toolbar)Toolbar mToolbar;
    @Bind(R.id...._recycler)RecyclerView.Recycler mRecycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout....);
        ButterKnife.bind(this);
    }

翻了下源码,该是这里的问题

if (!isSubtypeOfType(elementType, VIEW_TYPE) && !isInterface(elementType)) {

  error(element, "@%s fields must extend from View or be an interface. (%s.%s)",
      Bind.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName());
  hasError = true;
}

难道拿RecyclerView 不当View?困惑

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
大家讲道理

@Bind(R.id...._recycler)RecyclerView.Recycler mRecycler;这行代码好像有问题。
应该是@Bind(R.id...._recycler)RecyclerView mRecyclerView;Bar

大家讲道理

@Bind(R.id...._recycler)RecyclerView.Recycler mRecycler;

Here you are not using RecyclerView, but RecyclerView’s internal class Recycler, and Recycler does not inherit from View. You probably wrote it wrong.

刘奇

After working on it for a while, I found out, it’s so embarrassing, .Recycler studio is associated with it. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!