首页 > 其他 > 详细

使用ButterKnife无法inject view的解决办法

时间:2015-01-04 16:42:32      阅读:600      评论:0      收藏:0      [点我收藏+]

使用ButterKnife做android开发时,发现无法inject,如下,tvInfo总是null。

	@InjectView(R.id.textView1Info) TextView tvInfo;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		
		ButterKnife.inject(this);
		tvInfo.setText("test");// tvInfo is null.
	}

 

后来在官网上找到解决办法,如下:

http://jakewharton.github.io/butterknife/ide-eclipse.html

 

Eclipse Configuration

  1. Right click on your project in the Package Explorer. Head to Java Compiler → Annotation Processing and check "Enable project specific settings".

     

    Ensure the other annotation processing settings are the same as shown below:

    技术分享

  2. Expand the Annotation Processing section and select Factory Path. Check "Enable project specific settings" and then click "Add JARs…". Navigate to the project‘s libs/ folder and select the Butter Knife jar.

    技术分享

  3. Click "Ok" to save the new settings. Eclipse will ask you to rebuild your project to which you should click "Yes"
  4. Make sure that the .apt_generated/ folder is in your project root. It should contain files like YOURACTIVITY$$ViewInjector.java. If these files are not present trigger a clean build by selected Project → Clean. This folder and files should not be checked into revision control.
  5. Lastly, under "Java Compiler", make sure that the Compiler compliance level is set to Java version 1.6 at minimum.

使用ButterKnife无法inject view的解决办法

原文:http://www.cnblogs.com/yahb/p/4201275.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!