Hi
Literally from the JavaDoc
(http://java.sun.com/j2se/1.4/docs/api/java/lang/IllegalStateException.html
).
"Signals that a method has been invoked at an illegal or inappropriate time.
In other words, the Java environment or Java application is not in an
appropriate state for the requested operation."
To make it a little easier, we can explain in the context of an example.
I'll use the servlet api (as this is a servlets forum).
The ServletResponse class has two methods for accessing the output stream to
the client:
* getOutputStream() - returns a ServletOutputStream that can be used as a
raw OutputStream, or wrapped in a suitable output object to return data to
the client;
* getWriter() - returns a PrintWriter object that we can use to write text
back to the client.
Obviously we do not call both - we decide which is most suitable for
returning data to the client and call the appropriate method. It is
"illegal" to call the other method once one of them has been called. IE
once you have made the decision on what you are going to send back and
called the appropriate method, the response object is then ready to send
that type of data back and so you cannot then call the other method to write
different data back to the client.
Hence to prevent programmers making this mistake, the IllegalStateException
will be thrown if, upon calling getOutputStream or getWriter the other
method has previously been called in this request. Once either method has
been called, the response object is not in a state that allows it to have
the other method called, so the IllegalStateException is thrown.
Hope this makes some sense.
Andrew
Professional Java Servlets 2.3
http://www.amazon.com/exec/obidos/ASIN/186100561X
http://www.amazon.co.uk/exec/obidos/ASIN/186100561X
-----Original Message-----
From: Hi Servlet [mailto:freeservlet@y...]
Sent: 29 July 2002 02:35
To: Servlets
Subject: [servlets] java.lang.IllegalStateException
Hi,
May i know what does java.lang.IllegalStateException means?
Thanx