JSP, Singleton and NoClassDefFoundError

P

ppowell

From http://www.mycgiserver.com/~ppowell/chat.jsp:

Code:
<%@ page import="java.io.*, java.net.*, java.util.*, java.util.regex.*" %>
<%@ page import="javax.servlet.*, javax.servlet.http.*" %>
<%@ page import="ppowell.*" %>

I got it to the point where it seems to be ok and receives the classes. However, upon submitting a nickname it will go to the code snippet that instantiates a NicknameBin instance:

Code:
// CHECK TO SEE IF A DUPLICATE NICK EXISTS IN THE SINGLETON INSTANCE OF NicknameBin
if (hasEnteredNick) {
NicknameBin nick = NicknameBin.getNicknameBin(); // CREATE INSTANCE
try {
// PUT INTO TRY BLOCK TO PREVENT NullPointerException ERROR FROM NOT BEING CAUGHT
if (!nick.isFoundNickname(request.getParameter("nick")) && nick.getNicknameBinSize() > 0) {
hasEnteredNick = false;
errorMsg = "<li>" + ChatGlobals.font + "<font color=cc0000>Your nickname already exists please enter another</li></font></font><p>";
} else if (nick.getNicknameBinSize() + 1 > NicknameBin.MAX_NICKNAMES) {
hasEnteredNick = false;
errorMsg = "<li>" + ChatGlobals.font + "<font color=cc0000>Channel is full (capacity: " + NicknameBin.MAX_NICKNAMES + ")</li></font></font><p>";
}
} catch (Exception e) {} // DO NOTHING NO INSTANCE EXISTS THUS NO DUP
}
//---END OF DUP NICK/CHANNEL FULL BLOCK------------------------------------------------

Line 38:
Code:
 NicknameBin nick = NicknameBin.getNicknameBin(); // CREATE INSTANCE

NicknameBin.class is a Singleton Vector instance I designed so that every servlet and JSP page will call only one Vector instance of nicknames for the chatroom. I figured it would throw a NullPointerException if nothing is in the Vector so I thought I caught that one, but NoClassDefFoundError?? I am at a loss to this one!

Code:
500 Servlet Exception
java.lang.NoClassDefFoundError: ppowell/NicknameBin
at __27eppowell._chat__jsp._jspService(/~ppowell/chat.jsp:38)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:341)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:268)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:543)


--------------------------------------------------------------------------------
Resin 2.1.0 (built Tue Mar 26 14:12:50 PST 2002)

What kind of a workaround would you recommend at this point? I don't feel I should put the NicknameBin instantiation line 38 into the try{} block since I must have an instance created if it has not been done so already; nothing has to be in the Vector but it must exist.

Here is a snippet of the NIcknameBin.class file and how I built it:

Code:
/**
* @version JSDK 1.4
* @author Phil Powell
*/

package ppowell;

import java.util.Vector;

/**
* Bin to store nicknames for chat. Singleton Design Pattern.
*
*/
public class NicknameBin extends Vector {


//-------------------------- --* PROPERTIES *-- -----------------------------

/**
* private static final integer to contain maximum amount of nicknames allowed
*/
public static final int MAX_NICKNAMES = 50; // PUBLIC STATIC FINAL INT PROPERTY

/**
* Create private instance of this class
*/
private static NicknameBin instance = new NicknameBin(); // PRIVATE STATIC INSTANCE

//------------------------- --* END OF PROPERTIES *-- -----------------------


/**
* private constructor
*/
private NicknameBin() {} // CONSTRUCTOR

/**
* @return only one NicknameBin instance
*/
public static NicknameBin getNicknameBin() { // SINGLETON INSTANTIATOR METHOD
return instance;
}

/**
* prevent cloning of this class by overriding java.util.Vector.clone() method
*/
public Object clone() { // SINGLETON VECTOR CLONE PREVENTION METHOD
throw new UnsupportedOperationException();
}

// OTHER METHODS HERE
}

So yet another stumbling point whereby I am a bit unskilled to OO, sorry for so many questions.

Phil
 
C

Christophe Vanfleteren

ppowell wrote:

<snip code>

Do not multi post please. And for beginners such as yourself, c.l.j.help is
the better newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top