这是一个非常愚蠢的编译器错误,我想知道是否有一种简单的方法来抑制它(例如使用注释)?
错误发生在setCustomAnimations()
的第二个参数上。错误是:Expected resource of type anim
。
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
int exit_animation = current_popup == null ? 0 : current_popup.getExitAnimation();
transaction.setCustomAnimations( fragment.getEnterAnimation(), exit_animation ); //ERROR
如果我将三元线扩展为以下任一项,则错误消失。
int exit_animation;
if ( current_popup == null )
exit_animation = 0;
else
exit_animation = current_popup.getExitAnimation();
或者:
int exit_animation = 0;
if ( current_popup != null )
exit_animation = current_popup.getExitAnimation();
答案 0 :(得分:1)
抑制错误的解决方案是:
@AnimRes
int exit_animation = current_popup == null ? 0 : current_popup.getExitAnimation();
在评论中归功于CommonsWare。