photo-editor-android icon indicating copy to clipboard operation
photo-editor-android copied to clipboard

Attempt to invoke virtual method 'void android.graphics.Canvas.drawColor(int, android.graphics.PorterDuff$Mode)' on a null object reference

Open kleysonr opened this issue 6 years ago • 5 comments

You can use the app sample to simulate the error.

After the photo editor start, if we click on the "Clear All" button as the first action on the editor the following error happen:

2019-05-14 13:17:52.297 11032-11032/com.ahmedadeltito.photoeditor E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ahmedadeltito.photoeditor, PID: 11032
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawColor(int, android.graphics.PorterDuff$Mode)' on a null object reference
        at com.ahmedadeltito.photoeditorsdk.BrushDrawingView.clearAll(BrushDrawingView.java:121)
        at com.ahmedadeltito.photoeditorsdk.PhotoEditorSDK.clearAllViews(PhotoEditorSDK.java:184)
        at com.ahmedadeltito.photoeditor.PhotoEditorActivity.clearAllViews(PhotoEditorActivity.java:216)
        at com.ahmedadeltito.photoeditor.PhotoEditorActivity.onClick(PhotoEditorActivity.java:340)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25885)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

kleysonr avatar May 14 '19 16:05 kleysonr

hey man i can't complie that library can u send me your working project

Himanshu507 avatar Jun 30 '19 11:06 Himanshu507

I dont have the project anymore, I was just testing the lib.

But I created a new project and copied and pasted any code, file and configuration from the sample to my project to get it working :(

kleysonr avatar Jul 01 '19 11:07 kleysonr

Hey do you have any photo editing project? Because i'm facing problems in this area.

Himanshu507 avatar Jul 01 '19 11:07 Himanshu507

Sorry, I dont.

kleysonr avatar Jul 01 '19 17:07 kleysonr

@kleysonr
please update this method void clearAll() { if(drawCanvas!=null){ drawCanvas.drawColor(0, PorterDuff.Mode.CLEAR); invalidate(); }

}

in BrushDrawingView class and it will fix it

mrabelwahed avatar Jun 15 '20 08:06 mrabelwahed