본문 바로가기

Programming/Error Note

[Android] java.lang.IllegalMonitorStateException: object not locked by thread before notify()

[Android] java.lang.IllegalMonitorStateException: object not locked by thread before notify()

  • Problem

    : lock을 걸지 않았을 때 발생하는 에러(wait도 마찬가지로 발생)

 
java.lang.RuntimeException: Unable to start activity ComponentInfo{kr.co.foodfly.viewtest/kr.co.foodfly.viewtest.BlogActivity}: java.lang.IllegalMonitorStateException: object not locked by thread before notify()
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.IllegalMonitorStateException: object not locked by thread before notify()
        at java.lang.Object.notifyAll(Native Method)
        at kr.co.foodfly.viewtest.BlogActivity.onCreate(BlogActivity.java:80)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988
        at android.app.ActivityThread.-wrap14(ActivityThread.java
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631
        at android.os.Handler.dispatchMessage(Handler.java:102
        at android.os.Looper.loop(Looper.java:154
        at android.app.ActivityThread.main(ActivityThread.java:6682)

  • Solution

    synchoronized를 이용

 
xxxxxxxxxx
synchronized (mLock) {
    ...
    mLock.notifyAll(); // mLock.wait();
}