转载请注明 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));
问题暂时解决,如果读者有更好的解决方案,欢迎留言,谢谢。