使用三元运算符时预期的动画类型资源
Expected resource of type anim when using ternary operator
这是一个非常愚蠢的编译器错误,我想知道是否有一种简单的方法来抑制它(例如使用注释)?
错误发生在 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();
抑制错误的解决方法是:
@AnimRes
int exit_animation = current_popup == null ? 0 : current_popup.getExitAnimation();
在评论中感谢 CommonsWare。
这是一个非常愚蠢的编译器错误,我想知道是否有一种简单的方法来抑制它(例如使用注释)?
错误发生在 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();
抑制错误的解决方法是:
@AnimRes
int exit_animation = current_popup == null ? 0 : current_popup.getExitAnimation();
在评论中感谢 CommonsWare。