`
zhangym124
  • 浏览: 338751 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

androidannotations Eclipse下报引用不到框架生成类错误的解决方案

阅读更多

转载请注明 http://xuantan.iteye.com/admin/blogs/1828621

 

androidannotations Eclipse下报引用不到框架生成类错误的解决方案,如下:

Intent intent = new Intent(this,OtherPersonMessageActivity_.class);

这样eclipse会报找不到OtherPersonMessageActivity_.class的错误。

经查阅,这个bug已经遗留很久,无论是在eclipse社区还是在androidannotations社区都有人报告过此bug,但是至今仍没有一个很好的解决方案。

经网上查阅参考,笔者自己写了一个工具方法,仅供参考:

public class GeneratedClassUtils {
	
	@SuppressWarnings("rawtypes")
	public static Class get(Class clazz) {

		if (clazz == null) {
			return null; 
		}
		if (clazz.getCanonicalName().endsWith("_")) {
			return clazz;
		}
		
		String name = clazz.getCanonicalName() + "_";
		
		try {
			Class result = Class.forName(name);
			return result;
		} catch (ClassNotFoundException e) {
			new RuntimeException("Cannot find class for" + name, e);
		}
		
		return null;
	}

}

 调用时如下:

Intent intent = new Intent(this,GeneratedClassUtils.get(OtherPersonMessageActivity.class));

 

问题暂时解决,如果读者有更好的解决方案,欢迎留言,谢谢。

2
0
分享到:
评论
1 楼 非诚勿扰男嘉宾 2014-06-20  
引用整个包就好了,不用具体类

相关推荐

Global site tag (gtag.js) - Google Analytics