我有一堂课如下:
public class Element extends Activity
{
public float mX;
public float mY;
public void animate(long elapsedTime)
{
mX += mSpeedX * (elapsedTime / 20f);
mY += mSpeedY * (elapsedTime / 20f);
setmX(mX);
setmY(mY);
checkBorders();
}
public void setmX(float mX)
{
Log.i("this.mX","mY at setmX read is :"+this.mX ); **//Line 1**
this.mX = mX;
}
public float getmX() {
Log.i("mX","mX in getmX read is :"+mX ); **//Line 2**
return mX;
}
public void setmY(float mY) {
this.mY = mY;
Log.i("this.mY","mY at setmY read is :"+this.mY ); **//Line 3**
}
public float getmY() {
Log.i("mY","mY in getY read is :"+mY ); **//Line 4**
return mY;
}
}
我还有一堂课
public class Panel extends SurfaceView implements SurfaceHolder.Callback
{
int x = 100;
int y = 0;
public float xval;
public float yval;
@Override
public boolean onTouchEvent(MotionEvent event)
{
Element element = new Element();
float x = event.getX();
float y = event.getY();
Log.i("x","x in panel is :"+x);
//toast tos = new toast();
xval = element.getmX();
Log.i("xval","xval in playactivity obtained is :"+xval ); **//Line 5**
yval = element.getmY();
Log.i("yval","yval in playactivity obtained is :"+xval ); **//Line 6**
return super.onTouchEvent(event);
}
第 2、4、5 和 6 行将值显示为零。我不想这样做。下面是 logcat 图像。
我在访问说明符中犯了错误吗?