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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:39:02

问题


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:


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!



来源:https://stackoverflow.com/questions/26987728/java-lang-illegalargumentexceptionat-android-view-surface-unlockcanvasandpostn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!