我的游戏有问题 . 我有一个主要活动,它显示了我绘制游戏的表面视图 . 现在我想将数据从我的主要活动传递给一个类,但每次我尝试这个我得到一个错误,在LogCat中我看到错误发生在我传递数据的行上 . 这里是我的Code MainActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
public boolean onTouchEvent(MotionEvent event) {
currentX = event.getX();
currentY = event.getY();
if(event.getAction() == MotionEvent.ACTION_DOWN){
touchDisplay = true;
banka = new Banka(currentX, currentY, touchDisplay);
}
if(event.getAction() == MotionEvent.ACTION_UP){
touchDisplay = false;
banka = new Banka(currentX, currentY, touchDisplay);
}
return super.onTouchEvent(event);
}
收到数据的类:
public class Banka {
public GameView gameView;
public float currentX = 0;
public float currentY = 0;
public boolean touchDownTrue = false;
public Banka (float x, float y, boolean touch){
this.currentX = x;
this.currentY = y;
this.touchDownTrue = touch;
gameView.isReady();
}
这里是我的LogCat错误:
这里的logcat:
带有未捕获异常的线程退出(group = 0x4001b188)未捕获的处理程序:由于com.whlabs.nameless.Banka上的未捕获的异常java.lang.NullPointerException而导致的线程主要退出 . (Banka.java:14)位于com.whlabs.nameless.MainActivity在Android的com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1643)的android.app.Activity.dispatchTouchEvent(Activity.java:2064)的.onTouchEvent(MainActivity.java:31) . 在Android.app.A.运行时,在android.app.La上运行Android.os.Handler.dispatchMessage(Handler.java:99)的View.ViewRoot.handleMessage(ViewRoot.java:1691),在android.app.ActivityThread.main的android.os.Looper.loop(Looper.java:123) (ActivityThread.java:4363)java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:521)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller .run(ZygoteInit.java:860)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)at dalvik.system.NativeStart.main(Native Method)