Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android studio中的错误警告_Android_Android Studio_Warnings - Fatal编程技术网

android studio中的错误警告

android studio中的错误警告,android,android-studio,warnings,Android,Android Studio,Warnings,Android studio在下面的代码中显示警告“永远不要使用方法setFoo”: public void setFoo(float foo) { mFoo = foo; invalidate(); } protected void startFooProcess() { ObjectAnimator animator = ObjectAnimator.ofFloat(this, "foo", 1.0f, 0.0f); animator.setDuration

Android studio在下面的代码中显示警告“永远不要使用方法setFoo”:

public void setFoo(float foo) {
    mFoo = foo;
    invalidate();
}

protected void startFooProcess() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(this, "foo", 1.0f, 0.0f);
    animator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animator.setTarget(this);
    animator.start();
}

但是我正在使用object animator,如何消除这种警告?

如果你点击
setFoo
方法名称,你会得到一个黄色灯泡图标,你可以点击它来获得快速修复图标。作为一种快捷方式,方法名称中带有插入符号,您可以使用“显示意图操作”的组合键,即我使用的默认Mac键映射上的Alt+Enter

快速修复“Safe delete'setFoo(float)'”不是您想要的,但是您可以通过键盘或单击右箭头来扩展它以查看更多选项。显示可用于禁用检查的选项。截图:

文件>使缓存无效/重新启动

要解决这个问题


您可以看到这一点

这与其说是一个解决方案,不如说是一个问题,因为suppress for method的观点创建了注释“@SuppressWarnings(“UnusedDeclaration”)”,但这会弄脏代码,类的选项superss对所有类都做同样的事情,禁用选项不是一个好主意,因为它不可能找到真正的未使用的方法…虽然所有这些都是真的,但我不确定您在这里可以合理地期望什么。对于禁用检查,您有很多不同的选择,每个都有优点和缺点。我唯一能想到的另一件事是在某处包含一个伪类或方法,该类或方法调用该方法以绕过检查,但这也有缺点。是的,我同意,我期望的是一个不改变源代码的解决方案。例如,我在应用程序根文件夹的lint.xml文件中的一些配置中修复了lint的其他问题。我认为这是一个很好的解决办法。检查似乎只有一半的时间有效。我甚至收到关于公共方法的警告,它们不在同一个类/包中使用……荒谬。@slinden77这是一个bug。使用文件>使缓存无效来解决此问题-但这将清除本地文件历史记录。看到这个你可以添加@SuppressWarnings({“UnusedDeclaration”})谢谢这对我来说很有效,它让我发疯了:)