Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NoClassDefFoundError

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a servlet and it gets stuck at a certain line and shots out:
gsptech.portal.servlets.ImageServlet.GIF(ImageServlet.java:51)
*********
The ine above in my servlet is where it gets stuck line # 51 which is:
image = Jimi.getImage(f);
I thought it was because the JIMI jar was not in the folder, but it not it when I take that out the error gets more specific. I listed the message at the bottom. Works great for Windows just not Unix and I hae code for jpg. & GIF, it works finf for jpg. I have listed the code under the error message:
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.Toolkit$2.run(Toolkit.java:512)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:503)
at com.sun.jimi.core.Jimi.getImage(Jimi.java:201)
at com.sun.jimi.core.Jimi.getImage(Jimi.java:190)
at gsptech.portal.servlets.ImageServlet.GIF(ImageServlet.java:51)
at gsptech.portal.servlets.ImageServlet.doGet(ImageServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
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.Ajp12Interceptor.processConnection(Ajp12Interceptor.java:221)
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)
*********************************
package gsptech.portal.servlets;
import java.lang.*;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.*;
import java.util.Properties;
import gsptech.portal.biz.*;
import gsptech.portal.beans.*;
import java.sql.Timestamp;
import java.net.*;
import java.awt.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.IOException;
import com.sun.jimi.core.*;
public class ImageServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{


String file = req.getParameter("image");
int start = file.lastIndexOf('.') + 1;
int end = file.length();
String ext = "";

//Make sure that an extension exists
if (start != 0)
{
ext = file.substring( start, end );
System.out.println("@@@@@@@@@@@@@@@@@@@@@@" + ext);
if( ext.equalsIgnoreCase("jpg") | ext.equalsIgnoreCase("jpeg"))
JPEG(file, res);

if (ext.equalsIgnoreCase("gif"))
GIF(file, res);
}
}
private void GIF(String f, HttpServletResponse res)
{
try
{System.out.println("1ssssssssssssssssss" + f);
Image image = null;
System.out.println("2--------------------" + f);
image = Jimi.getImage(f);
System.out.println("2.555555555ssssssssssssssssss" + f);
OutputStream out = res.getOutputStream();
System.out.println("3ssssssssssssssssss" + f);
net.jmge.gif.Gif89Encoder gifenc = new net.jmge.gif.Gif89Encoder(image);
System.out.println("4ssssssssssssssssss" + f);
gifenc.encode(out);
System.out.println("5ssssssssssssssssss" + f);
}
catch(Exception e)
{
System.out.println("Problem rendering image" + e);
}
}
private void JPEG(String f, HttpServletResponse res)

{
try
{
FileInputStream fis = new FileInputStream(f);

JPEGImageDecoder decode = JPEGCodec.createJPEGDecoder((InputStream)fis);

BufferedImage img = decode.decodeAsBufferedImage();

OutputStream out = res.getOutputStream();

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(img);
System.out.println("ssssssssssssss" + f);
}
catch(Exception e)

{
System.out.println("Problem rendering image" + e);
}
}
}
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony
It looks like you're getting the file name from a web form and using it in the getImage method. If it is working in wndows adn ot in unix it is most likely a case sensitivity issue. You might want to convert the file name passed in to all upper or lower case dependng on how they are in the file system.
hope that helps
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get an error message when it cannot find the file, and liek I said it works for the JPEG part just not GIF.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic