开发者

how to solve warning in android program "never read locally"

Why I am getting a warning saying:

The field testscreen.ScaleAnimToShow.mVanishAfter is never read locally testscreen.java /testscreen/src/com/testscreen  line 186    Java Problem

from the following code?

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);
       }


That's because you have the field that occupies some space in memory but which is never read anywhere in your program.

You can resolve this warning:

  • Remove this field. If you don't use it, don't keep it in your code.
    or
  • Add @SuppressWarnings("unused") annotation. This may be useful when this field is used via annotation, or you want to keep it in code for other reasons.
@SuppressWarnings("unused")
private boolean mVanishAfter = false;


You have a private class member, mVanishAfter, that is never read. Since it is private in the class, the IDE can see it is never used, which appears to be a mistake.


Because you never read mVanishAfter. At least in the code you posted, you only ever assign to it, and because it is private it can never be read from anywhere else. A variable isn't "read" when it is assigned to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜