java - Android Live Wallpaer crashed(NullPointerException, canvas is a null object)but I cannot find where -


this question has answer here:

04-14 12:04:30.971 1639-1938/system_process i/windowmanager: destroying surface surface(name=media:com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.livewallpaperchange) called com.android.server.wm.windowstateanimator.destroysurface:2014 com.android.server.wm.windowstateanimator.destroysurfacelocked:881 com.android.server.wm.windowstate.removelocked:1449 com.android.server.wm.windowmanagerservice.removewindowinnerlocked:2478 com.android.server.wm.windowmanagerservice.removewindowlocked:2436 com.android.server.wm.windowmanagerservice.removewindowlocked:2305 com.android.server.wm.windowmanagerservice.removewindow:2300 com.android.server.wm.session.remove:193  04-14 12:04:30.990 3852-3852/tianranwang.livewallpaper d/mainservice: dispose 04-14 12:04:31.018 1639-1990/system_process i/windowmanager: destroying surface surface(name=tianranwang.livewallpaper.mainservice) called com.android.server.wm.windowstateanimator.destroysurface:2014 com.android.server.wm.windowstateanimator.destroysurfacelocked:881 com.android.server.wm.windowstate.removelocked:1449 com.android.server.wm.windowmanagerservice.removewindowinnerlocked:2478 com.android.server.wm.windowmanagerservice.removewindowlocked:2436 com.android.server.wm.windowmanagerservice.removewindowlocked:2305 com.android.server.wm.windowmanagerservice.removewindow:2300 com.android.server.wm.session.remove:193             --------- beginning of crash 04-14 12:04:31.020 3852-4240/tianranwang.livewallpaper e/androidruntime: fatal exception: animation thread           process: tianranwang.livewallpaper, pid: 3852           java.lang.nullpointerexception: attempt invoke interface method 'void android.view.surfaceholder.unlockcanvasandpost(android.graphics.canvas)' on null object reference               @ processing.a2d.pgraphicsandroid2d.enddraw(unknown source)               @ processing.core.papplet.handledraw(unknown source)               @ processing.core.psurfacenone.calldraw(unknown source)               @ processing.core.psurfacenone$animationthread.run(unknown source) 

on interface “set wallpaper”, rotated screen , sketch(drawing live wallpaper) restarted, , app crashed(not crashed), , sketch(live wallpaper) kept running on background..

could 1 give me hint? in advance.


the source code ,that have found in processing.a2d.pgraphicsandroid2d.enddraw()

from https://github.com/processing/processing-android/tree/master/core/src/processing

  public void enddraw() {     if (bitmap == null) return;      // hm, mark pixels changed, because instantly full     // copy of pixels surface.. that's kind of mess.     //updatepixels();  //    if (primarygraphics) { //      if (canvas != null) { //        parent.getsurfaceholder().unlockcanvasandpost(canvas); //      } //    }      if (primarygraphics) {       surfaceholder holder = parent.getsurface().getsurfaceholder();       if (holder != null) {         canvas screen = null;         try {           screen = holder.lockcanvas(null);           if (screen != null) {             screen.drawbitmap(bitmap, new matrix(), null);           }         } {           if (screen != null) {             try {               holder.unlockcanvasandpost(screen);             } catch (illegalstateexception ex) {             }           }         }       }      } else {       // todo overkill tasks...       loadpixels();     }      // marking modified, , calling updatepixels() in     // super class, sets mx1, my1, mx2, my2     // coordinates of modified area. avoids doing     // full copy of pixels surface in this.updatepixels().     setmodified();     super.updatepixels();   } 

the code above may cause nullpointerexception.


i dont have problem now, because update new version of processing library..and code above new version of lib. (i cannot see code old version)

what nullpointer?

a nullpointer common exception in java. happens when try make calls instance hasn't been initiated. consider this:.

canvas c; c.drawrect(...); 

this doing. though code may different(and there thread involved.

before unlock , post have lock canvas. this:

canvas canvas = sf.lockcanvas(); 

canvas says itself, , sf surfaceview. surfaceview can replaced view(view, surfaceview, etc).

so if add line above, make canvas reference , not null, , exception solved


change this:

screen = holder.lockcanvas(null); 

to this

screen = holder.lockcanvas(); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -