IllegalMonitorStateException [英] IllegalMonitorStateException

查看:77
本文介绍了IllegalMonitorStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行我们的程序时,我们得到一个类型为java.lang.IllegalMonitorStateException的异常.在Java6 API网站上,它说有一个构造函数,提供了有关异常的详细信息:IllegalMonitorStateException(String s)

When running our program we get an exception of type java.lang.IllegalMonitorStateException. On Java6 API website, it says there is a constructor that gives a details about the exception: IllegalMonitorStateException(String s)

我们如何使用它来更好地了解错误在代码中的位置?我们还能做些什么(除了我们目前正在做的大量调试工作之外)来找出失败的函数或行?

How can we use this to get a better idea of where the bug is in our code? Is there anything else we can do (besides lots of debugging which we're currently doing) to pinpoint the function or line that failed?

推荐答案

在创建异常时必须提供详细信息(构造函数,对吗?),如果不创建该异常,则无法为您提供详细信息.

The details must be given when the Exception is created (Constructor, right?) and if you are not creating it, there is no way for you to provide the details.

您可以分析异常的StackTrace.它显示了引起异常的类,方法和源代码行.

You can analize the StackTrace of the Exception. It shows the classes, methods and souce line which were called to cause the Exception.

IllegalMonitorStateException的一个原因是试图等待对象而没有对其进行同步.参见 Javadoc .

One cause for the IllegalMonitorStateException is trying to wait on an Object without having synchronized on it. See the Javadoc.

还有其他可能的原因,某些库/外部代码可能会引发Exception.我认为只有StackTrace可以帮忙...

There are other possible causes and the Exception may be thrown by some library/external code. I think only the StackTrace can help...

这篇关于IllegalMonitorStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆