为什么我收到警告说:
The field testscreen.ScaleAnimToShow.mVanishAfter is never read locally testscreen.java /testscreen/src/com/testscreen line 186 Java Problem
来自以下代码?
public class ScaleAnimToShow extends ScaleAnimation{
private View mView;
private LayoutParams mLayoutParams;
private int mMarginBottomFromY, mMarginBottomToY;
private boolean mVanishAfter = false;
public ScaleAnimToShow(float toX, float fromX, float toY, float fromY, int duration, View view,boolean vanishAfter){
super(fromX, toX, fromY, toY);
openLayout = view;
setDuration(duration);
mView = view;
mVanishAfter = vanishAfter;
mLayoutParams = (LayoutParams) view.getLayoutParams();
mView.setVisibility(View.VISIBLE);
int height = mView.getHeight();
//mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin + height;
//mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) + height;
mMarginBottomFromY = 0;
mMarginBottomToY = height;
Log.v("CZ",".................height..." + height + " , mMarginBottomFromY...." + mMarginBottomFromY + " , mMarginBottomToY.." +mMarginBottomToY);
}
答案 0 :(得分:4)
那是因为你的字段在内存中占用了一些空间,但在程序中的任何地方都无法读取。
您可以解决此警告:
@SuppressWarnings("unused")
注释。当通过注释使用此字段时,或者由于其他原因希望将其保留在代码中时,这可能很有用。@SuppressWarnings("unused")
private boolean mVanishAfter = false;
答案 1 :(得分:2)
你有一个永远不会读的私人类成员mVanishAfter。由于它在类中是私有的,因此IDE可以看到它从未被使用过,这似乎是一个错误。
答案 2 :(得分:0)
因为您从未阅读mVanishAfter
。至少在您发布的代码中,您只能分配给它,并且因为它是私有的,所以永远不能从其他任何地方读取它。分配给变量时,变量不会被“读取”。