我的 Android 应用程序是我为学校做的一个小游戏。当我从菜单启动到游戏屏幕时,它是在另一个类中创建的画布,它停止运行。到目前为止,我在此站点上没有找到任何有用的其他线程。帮助表示赞赏!代码:画布类:
public class CanvasClass extends View {
Bitmap mBackground, BackScaled,bobOri, bobScale;
int width, height,bobWidth = 22, bobHeight = 62;
DisplayMetrics displaymetrics;
public CanvasClass(Context context) {
super(context);
((Activity) getContext()).requestWindowFeature(Window.FEATURE_NO_TITLE);
((Activity) getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
DisplayMetrics displaymetrics = new DisplayMetrics();
height =displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
mBackground = BitmapFactory.decodeResource(getResources(), R.drawable.background);
BackScaled = Bitmap.createScaledBitmap(mBackground, width, height,true);
bobOri = BitmapFactory.decodeResource(getResources(),R.drawable.bobertfront);
bobScale = Bitmap.createScaledBitmap(bobOri, bobWidth,bobHeight, true);
}
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawBitmap(BackScaled,0,0,null);
canvas.drawBitmap(bobScale,20,400,null);
}
}
我不知道您还需要什么来回答我的问题,请尽管问,我很新。
10-19 08:48:45.973: D/dalvikvm(790): GC_FOR_ALLOC freed 69K, 5% free 2599K/2720K, paused 42ms, total 46ms
10-19 08:48:45.993: I/dalvikvm-heap(790): Grow heap (frag case) to 4.049MB for 1536016-byte allocation
10-19 08:48:46.053: D/dalvikvm(790): GC_FOR_ALLOC freed 2K, 3% free 4097K/4224K, paused 52ms, total 52ms
10-19 08:48:46.354: D/gralloc_goldfish(790): Emulator without GPU emulation detected.
10-19 08:48:53.734: I/Choreographer(790): Skipped 598 frames! The application may be doing too much work on its main thread.
10-19 08:48:56.485: D/AndroidRuntime(790): Shutting down VM
10-19 08:48:56.485: W/dalvikvm(790): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-19 08:48:56.584: E/AndroidRuntime(790): FATAL EXCEPTION: main
10-19 08:48:56.584: E/AndroidRuntime(790): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.paulsng.platformer/com.paulsng.platformer.GameActivity}: java.lang.NullPointerException
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.os.Looper.loop(Looper.java:137)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-19 08:48:56.584: E/AndroidRuntime(790): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 08:48:56.584: E/AndroidRuntime(790): at java.lang.reflect.Method.invoke(Method.java:525)
10-19 08:48:56.584: E/AndroidRuntime(790): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-19 08:48:56.584: E/AndroidRuntime(790): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-19 08:48:56.584: E/AndroidRuntime(790): at dalvik.system.NativeStart.main(Native Method)
10-19 08:48:56.584: E/AndroidRuntime(790): Caused by: java.lang.NullPointerException
10-19 08:48:56.584: E/AndroidRuntime(790): at android.view.DisplayInfo.getMetricsWithSize(DisplayInfo.java:340)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.view.DisplayInfo.getAppMetrics(DisplayInfo.java:321)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.view.Display.getMetrics(Display.java:525)
10-19 08:48:56.584: E/AndroidRuntime(790): at com.paulsng.platformer.CanvasClass.<init>(CanvasClass.java:23)
10-19 08:48:56.584: E/AndroidRuntime(790): at com.paulsng.platformer.GameActivity.onCreate(GameActivity.java:18)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.Activity.performCreate(Activity.java:5133)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-19 08:48:56.584: E/AndroidRuntime(790): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-19 08:48:56.584: E/AndroidRuntime(790): ... 11 more
10-19 08:49:00.114: I/Process(790): Sending signal. PID: 790 SIG: 9