Java.lang.IllegalMonitorStateException: unlocking an unregistered monitor on java.util.Random.nextGaussian (Random.java:187)

When calling the built-in nextGaussian method, an nextGaussian thrown: unlocking an unregistered monitor

 double dispersion = RAND.nextGaussian() * 0.2; 

which is inside

  @Override public void stroke(Canvas c, float x, float y) { } 

which is called here

 case MotionEvent.ACTION_MOVE: style.stroke(mCanvas, x, y); break; } return true; } 

then in Surface.java

  @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: getHistory().saveState(); break; } final float x = panHelper.translateX(event.getX()); final float y = panHelper.translateY(event.getY()); return controller.onTouch(event.getAction(), x, y); } 

Code Failure:

 java.lang.IllegalMonitorStateException: unlock of unowned monitor . 

Bump!

+4
source share
1 answer

I suspect this is an error in the OS (I get exactly the same error). You might try using a random number generator in a Gaussian generator. Here I found in some old code - Sorry, I can’t remember where I got it from.

 Random rand; Boolean RG_y2_valid = false; Double RG_y1; Double RG_y2; double rand_gauss() { double x1, x2, w; if (RG_y2_valid) { RG_y2_valid = false; return RG_y2; } do { x1 = 2.0 * rand.nextDouble() - 1.0; x2 = 2.0 * rand.nextDouble() - 1.0; w = x1 * x1 + x2 * x2; } while ( w >= 1.0 ); w = Math.sqrt( (-2.0 * Math.log( w ) ) / w ); RG_y1 = x1 * w; RG_y2 = x2 * w; RG_y2_valid = true; return RG_y1; } 
0
source

Source: https://habr.com/ru/post/1397327/


All Articles