Note that there are some explanatory texts on larger screens.

plurals
  1. POLive Wallpaper + bitmap + canvas
    primarykey
    data
    text
    <p>Helo everyone! I have this live wallpaper in witch I try to show a bitmap trough a canvas (the drawable resource is a 400k 1900x1200 jpg). It force-closes and I don't get why (it's my first Android project). These are the "important" bits:</p> <pre><code> wallEngine() { // CONSTRUCTOR &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; mStartTime = SystemClock.elapsedRealtime(); Log.v(Logcat, "Contructor ok"); } //====================================== INIT private final Runnable mDrawWall = new Runnable() { //=========== RUN public void run() { drawFrame(); } }; void drawFrame() { final SurfaceHolder holder = getSurfaceHolder(); Canvas c = null; try { c = holder.lockCanvas(); if (c != null) { // draw something updatePhysics(); doDraw(c); } } finally { if (c != null) holder.unlockCanvasAndPost(c); } // Reschedule the next redraw mHandler.removeCallbacks(mDrawWall); if (mVisible) { mHandler.postDelayed(mDrawWall, 5000); } } private void doDraw(Canvas canvas) { //backgroundImage.prepareToDraw(); canvas.drawBitmap(this.backgroundImage, 0, 0, null); } public void onCreate(SurfaceHolder surfaceHolder) { super.onCreate(surfaceHolder); surfaceHolder.setFormat(android.graphics.PixelFormat.RGBA_8888); BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; this.backgroundImage = BitmapFactory.decodeResource(getResources(), com.misca.livewallpapers.parang.R.drawable.a, options); //backgroundImage.prepareToDraw(); //setTouchEventsEnabled(true); Log.v(Logcat, "onCreate ok"); } </code></pre> <p>And the logcat errors when i try to run it on my phone are :</p> <pre><code>ERROR/AndroidRuntime(7722): FATAL EXCEPTION: main ERROR/AndroidRuntime(7722): java.lang.NullPointerException ERROR/AndroidRuntime(7722): at android.graphics.Canvas.throwIfRecycled(Canvas.java:957) ERROR/AndroidRuntime(7722): at android.graphics.Canvas.drawBitmap(Canvas.java:983) ERROR/AndroidRuntime(7722): at com.misca.livewallpapers.parang.liveWallpaper$wallEngine.doDraw(liveWallpaper.java:115) ERROR/AndroidRuntime(7722): at com.misca.livewallpapers.parang.liveWallpaper$wallEngine.drawFrame(liveWallpaper.java:75) ERROR/AndroidRuntime(7722): at com.misca.livewallpapers.parang.liveWallpaper$wallEngine.onSurfaceChanged(liveWallpaper.java:157) ERROR/AndroidRuntime(7722): at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:590) ERROR/AndroidRuntime(7722): at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:654) ERROR/AndroidRuntime(7722): at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:878) ERROR/AndroidRuntime(7722): at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61) ERROR/AndroidRuntime(7722): at android.os.Handler.dispatchMessage(Handler.java:99) ERROR/AndroidRuntime(7722): at android.os.Looper.loop(Looper.java:123) ERROR/AndroidRuntime(7722): at android.app.ActivityThread.main(ActivityThread.java:3848) ERROR/AndroidRuntime(7722): at java.lang.reflect.Method.invokeNative(Native Method) ERROR/AndroidRuntime(7722): at java.lang.reflect.Method.invoke(Method.java:507) ERROR/AndroidRuntime(7722): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) ERROR/AndroidRuntime(7722): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 03-23 00:26:42.309: ERROR/AndroidRuntime(7722): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Thank you! :)</p> <p>======================= News:</p> <pre><code> private void doDraw(Canvas canvas) { //backgroundImage.prepareToDraw(); if(this.backgroundImage!=null) canvas.drawBitmap(this.backgroundImage, 0, 0, null); else Log.v(Logcat, "null"); } </code></pre> <p>And seems the bitmap is null. Now i'm working with a 480x800 to ensure there are no memory problems. The app doesn't crash anymore with the if statement (empty black screen)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload