butterknife7.0.1使用

1、官网:http://jakewharton.github.io/butterknife/

 

Introduction

Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.

class ExampleActivity extends Activity {
  @Bind(R.id.title) TextView title;
  @Bind(R.id.subtitle) TextView subtitle;
  @Bind(R.id.footer) TextView footer;

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);
    ButterKnife.bind(this);
    // TODO Use fields...
  }
}


一看就明白了,这个东西就是让我们省去一些工作,来处理一些更有意义的事。

看上去挺简单的,并开始运行程序的时候报crashed,null pointed exception
原来是没有配制注解导致,按下图配制即可。

这样就可以顺利运行了。



posted @ 2016-02-23 14:55  jiduoduo  阅读(670)  评论(0编辑  收藏  举报