コードがキャンバスの初期化に到達すると、NullPointerException が発生します。キャンバスを作成するときに、空白のビットマップを渡しました。
これは、nullpointerexception が発生する私のコードです。
private static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight, ScalingLogic scalingLogic) {
Rect srcRect = calculateSrcRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight, scalingLogic);
Rect dstRect = calculateDstRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight, scalingLogic);
Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(), Config.ARGB_8888);
Canvas canvas = new Canvas(scaledBitmap);
canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG));
return scaledBitmap;
}
これはコードのスタック トレースです。
java.lang.RuntimeException: アクティビティ ComponentInfo{com.android.PhotoEditActivity} を開始できません: android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) での java.lang.NullPointerException android.app.ActivityThread.handleLaunchActivity(ActivityThread. java:2679) で android.app.ActivityThread.access$2300(ActivityThread.java:125) で android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) で android.os.Handler.dispatchMessage(Handler.java: 99) android.os.Looper.loop(Looper.java:123) で android.app.ActivityThread.main(ActivityThread.java:4627) で java.lang.reflect.Method.invokeNative(Native Method) で java.lang com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) の .reflect.Method.invoke(Method.java:521) com.android.internal.os.ZygoteInit.main(ZygoteInit.java) :616) dalvik.system.NativeStart.main(Native Method) で 原因: java.lang.NullPointerException at android.graphics.Canvas.(Canvas.java:82) at ImageManupulator.createScaledBitmap(ImageManupulator.java:101) at utils. ImageManupulator.ImageResizing(ImageManupulator.java:27) で android.PhotoEditActivity.updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java:211) で android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) ) android.widget.AdapterView.performItemClick(AdapterView.java:284) で android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) で android.app.ActivityThread .performLaunchActivity(ActivityThread.java:2627) ... 11 もっと見るmain(Native Method) 原因: java.lang.NullPointerException at android.graphics.Canvas.(Canvas.java:82) at ImageManupulator.createScaledBitmap(ImageManupulator.java:101) at utils.ImageManupulator.ImageResizing(ImageManupulator.java:27) ) android.PhotoEditActivity.updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java:211) で android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick (AdapterView.java:284) で android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) で android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11以上main(Native Method) 原因: java.lang.NullPointerException at android.graphics.Canvas.(Canvas.java:82) at ImageManupulator.createScaledBitmap(ImageManupulator.java:101) at utils.ImageManupulator.ImageResizing(ImageManupulator.java:27) ) android.PhotoEditActivity.updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java:211) で android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick (AdapterView.java:284) で android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) で android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11以上82) ImageManupulator.createScaledBitmap(ImageManupulator.java:101) で utils.ImageManupulator.ImageResizing(ImageManupulator.java:27) で android.PhotoEditActivity.updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java) :211) android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick(AdapterView.java:284) で android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app. Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 詳細82) ImageManupulator.createScaledBitmap(ImageManupulator.java:101) で utils.ImageManupulator.ImageResizing(ImageManupulator.java:27) で android.PhotoEditActivity.updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java) :211) android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick(AdapterView.java:284) で android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app. Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 詳細updatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java:211) で android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick(AdapterView.java:284) ) android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) で android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 もっと見るupdatePhoto(PhotoEditActivity.java:219) で android.PhotoEditActivity.access$0(PhotoEditActivity.java:211) で android.PhotoEditActivity$2.onItemClick(PhotoEditActivity.java:279) で android.widget.AdapterView.performItemClick(AdapterView.java:284) ) android.PhotoEditActivity.onCreate(PhotoEditActivity.java:128) で android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) で android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 もっと見る1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 もっと見る1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 もっと見る