• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the problem??

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting the following error when i try to load the JSP in my browser. can somebody let me know what is the problem?
ERROR:
Error: 500
Location: /examples/jsp/num/numguessByPrad.jsp
Internal Servlet Error:
javax.servlet.ServletException: Cannot create bean of class num.NumberGuessBeanNew
at jsp.num.numguessByPrad_10._jspService(numguessByPrad_10.java:74)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.ClassNotFoundException: class num.NumberGuessBeanNew : java.lang.ArithmeticException: / by zero
at java.beans.Beans.instantiate(Beans.java:211)
at java.beans.Beans.instantiate(Beans.java:51)
at jsp.num.numguessByPrad_10._jspService(numguessByPrad_10.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
The code for numguessByPrad.jsp
<%@ page import = "num.NumberGuessBeanNew" %>
<jsp:useBean id="numguess1" class="num.NumberGuessBeanNew" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess1.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess1.getNumGuesses() %> tries.<p>

<%numguess1.resetMain();%>

Care to <a href="numguessByPrad.jsp">try again</a>?
<% } else if (numguess1.getNumGuesses() == 0) { %>

Welcome to the Number Guess game modified by Pradnya.<p>
The Lower number will always start from 0. Enter the upper limit.<p>

<form method=get>
Enter the upper limit: <input type=text name=upper>
<input type=submit value="Submit">

<%
if ( request.getParameter("upper") != null ) {
%>
<%@ include file="next.jsp" %>
<%
}
%>


</form>



<% } else { %>
Good guess, but nope. Try <b><%= numguess1.getHint() %></b>.
You have made <%= numguess1.getNumGuesses() %> guesses.<p>

<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
The code for response.jsp
<%@ page import = "num.NumberGuessBeanNew" %>
<jsp:useBean id="numguess" class="num.NumberGuessBeanNew" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess.getNumGuesses() %> tries.<p>

<%numguess.resetMain();%>

Care to <a href="numguessByPrad.jsp">try again</a>?
<% } else if (numguess.getNumGuesses() == 0) { %>

Now guess what number is in my mind?<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>


<% } else { %>
Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
You have made <%= numguess.getNumGuesses() %> guesses.<p>

<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
and the code for NumberGuessBeanNew.java
package num;
import java.util.*;
public class NumberGuessBeanNew {
int answer;
boolean success;
String hint;
int numGuesses;
int upper1 = 0;

public NumberGuessBeanNew() {
resetMain();
}
public void setGuess(String guess) {
numGuesses++;
int g;
try {
g = Integer.parseInt(guess);
}
catch (NumberFormatException e) {
g = -1;
}
if (g == answer) {
success = true;
}
else if (g == -1) {
hint = "a number next time";
}
else if (g < answer) {
hint = "higher";
}
else if (g > answer) {
hint = "lower";
}
}
public void setUpper(String upper)
{

upper1 = Integer.parseInt(upper);
reset(upper1);

}

public boolean getSuccess() {
return success;
}
public String getHint() {
return "" + hint;
}
public int getNumGuesses() {
return numGuesses;
}
public void reset(int upper) {

answer = Math.abs(new Random().nextInt(upper) % upper) + 1;
success = false;
numGuesses = 0;
}

public void resetMain() {
answer = Math.abs(new Random().nextInt() % upper1) + 1;
success = false;
numGuesses = 0;
}


}
It's a time consuming process going through the code but please somebody take time to go through it & let me know the error.I am stuck due to this.
Thanks In advance..
Trupti
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.ClassNotFoundException
You don't have the class in the proper location.
If you don't have it in a jar, the NumberGuessBeanNew.class file goes in the
WEB-INF/classes/num
directory.
Otherwise, the jar file it's in goes in the
WEB-INF/lib directory.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by trupti nigam:
Hi,
javax.servlet.ServletException: Cannot create bean of class num.NumberGuessBeanNew
Root cause:
java.lang.ClassNotFoundException: class num.NumberGuessBeanNew : java.lang.ArithmeticException: / by zero


Well, you see here ClassNotFoundException so where is your num.NumberGuessBeanNew class file located? It should be in WEB-INF\classes\num dir.

Take care of that first and see where does this Arithmetic devide by zero Exception come from.
HTH
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that the first problem is gone..
In the browser the first jsp i.e. the numguessByPrad gets loaded but from this JSP i am invoking a new jsp called the response JSP . the moment i enter the upper limit & click on submit instead of getting the new JSP page i get the followning nullPointer exception.
Error: 500
Location: /examples/jsp/num/numguessByPrad.jsp
Internal Servlet Error:
org.apache.jasper.JasperException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:200)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:148)
at jsp.num.numguessByPrad_10._jspService(numguessByPrad_10.java:89)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.NullPointerException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:162)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:148)
at jsp.num.numguessByPrad_10._jspService(numguessByPrad_10.java:89)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Let me know where i am wrong.
Thanks in advance.
Trupti
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please somebody let me know why i am getting the null pointer exception.
I can't go further,
One correction to the include file action.
I have done little correction i.e.
<%@ include file="/jsp/num/next.jsp" %>
in the numguessByPrad.jsp
thanks,
Trupti
reply
    Bookmark Topic Watch Topic
  • New Topic