java.lang.IllegalArgumentException:at android.view.Surface.unlockCanvasAndPost(Native Method)

4.6k views Asked by At

I've searched about this problem for two days. I know that this is caused by some silly mistake but i'm unable to find that thing. It would be great, if someone helps me. Here is snippet

private void draw() {
        final SurfaceHolder holder = getSurfaceHolder();

        Canvas c = holder.lockCanvas();;

        try {
            update(c);
            updateText(c);     //These are the effects like snowing or bouncing
        } finally {
            if (c != null)
                holder.unlockCanvasAndPost(c);   //This is line no. 151
        }

        mHandler.removeCallbacks(drawRunner);
        if (mVisible) {
            mHandler.postDelayed(drawRunner, 10);
        }
    }

I think the problem is whithin above method. Here is logcat:

 11-18 11:29:15.145: E/AndroidRuntime(2845): java.lang.IllegalArgumentException
11-18 11:29:15.145: E/AndroidRuntime(2845):     at android.view.Surface.unlockCanvasAndPost(Native Method)

11-18 11:29:15.145: E/AndroidRuntime(2845):     at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)

11-18 11:29:15.145: E/AndroidRuntime(2845):     at com.example.livewallpaper.SnowEffect$MyBounce.draw(SnowEffect.java:151)

11-18 11:29:15.145: E/AndroidRuntime(2845):     at com.example.livewallpaper.SnowEffect$MyBounce.access$0(SnowEffect.java:141)

11-18 11:29:15.145: E/AndroidRuntime(2845):     at com.example.livewallpaper.SnowEffect$MyBounce$1.run(SnowEffect.java:55)
1

There are 1 answers

4
Paresh P. On BEST ANSWER

Figured out the problem.

If someone got stuck in same problem, here is the solution, it was a really silly mistake. Update your manifest file.

<activity
      android:name="com.yourpackage.Prefs"
      android:exported="true" >
      <intent-filter>
           <category android:name="android.intent.category.PREFERENCE" />
      </intent-filter>
</activity>

Don't forget to add android:exported="true". I missed it actually!