aspose file tools*
The moose likes Struts and the fly likes constructor problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "constructor problems" Watch "constructor problems" New topic
Author

constructor problems

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
In the action code below on the line tagged /** ERROR ON NEXT LINE **/
my call to the constructor fails. However when I call the SimpleMP3Read from within its own main it suceeds. Even trying to remember which objects are created on the stack within which scope, this still does not make any sense. Can someone explain what fundamental I am failing to see here? tia.

package samplemp3.actions;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;
import samplemp3.SimpleMP3Read;
import samplemp3.forms.*;

public class SampleMP3Action
extends Action {
SimpleMP3Read sampleMP3;
File mp3;
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) throws
IOException {
// SimpleMP3Read sampleMP3 = null;
SampleMP3Form sampleMP3Form = (SampleMP3Form) actionForm;
String fileName = sampleMP3Form.getFileName();
int sampleMilliSec = Integer.parseInt(sampleMP3Form.getNumOfMins());

String mp3Dir = servlet.getInitParameter("mp3-dir");
System.out.println("mp3Dir= " + mp3Dir);
if (mp3Dir == null || mp3Dir.equals("")) { //really should do this with Action errors or validate
try {
throw new ServletException(
"Invalid or non-existent mp3Dir context-param.");
}
catch (ServletException ex) {
System.out.println("testing if mp3Dir is null, should NOT be here");
ex.printStackTrace();
}
}
mp3 = new File(mp3Dir + "/" + fileName);
System.out.println("file: " + fileName);
System.out.println("mp3= " + mp3.toString()+" | the class is "+mp3.getClass());
System.out.println("Milliseconds: " + sampleMilliSec);

try {
System.out.println("in the try before the constructor "+mp3.toString());
/** ERROR ON NEXT LINE **/
sampleMP3 = new SimpleMP3Read(mp3); //this is my problem 0501003 cp
}
catch (BitstreamException ex) {
System.out.println("error creating the SampleMP3Read" + ex.toString());
}
catch (IOException ioe) {
System.out.println("Catching IOException after constructor");
ioe.getCause();
ioe.printStackTrace();
}

System.out.println("Frames = " + sampleMP3.getCountFrames());
System.out.println("Time= " + sampleMP3.getLength());

//create a temporary file on server for output.
Random psrng = new Random();
int[] prefix = null;
StringBuffer tmp = new StringBuffer("");
for (int loop = 0; loop < 3; loop++) {
prefix[loop] = psrng.nextInt(10);
tmp = tmp.append(loop);
}
String fprefix = tmp.toString();
String fsuffix = "mp3";
File temp = new File(mp3Dir + "/" + fprefix + fsuffix);

System.out.println("Output file name= " + temp);
//File temp = new File(args[1]);
//this frame calculation is INVALID if vbr is set. I control these recordings
int frames_sec = (int) (1 / sampleMP3.getMs_frame()) * 1000;
int sampleFrames = (int) (sampleMilliSec / sampleMP3.getMs_frame());
int sampleRangeFrames = sampleMP3.getCountFrames() - sampleFrames -
(2 * frames_sec);
int randomJumpFrame = psrng.nextInt(sampleRangeFrames); //in terms of frames
int stopFrame = randomJumpFrame + sampleFrames; //in terms of frames
float randomMilliSec = randomJumpFrame * sampleMP3.getMs_frame();
float stopMilliSec = (randomMilliSec + sampleMilliSec);

float startTime = randomMilliSec;
float endTime = stopMilliSec;
OutputStream output = new FileOutputStream(temp);
try {
sampleMP3.cutFragment(startTime, endTime, output);
}
finally {
output.close();
}
HttpSession session = request.getSession();
session.setAttribute("fileName", output);
session.setAttribute("file", mp3);

return actionMapping.findForward("sendToBrowser");
}


alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
you did not post your SimpleMP3Read.java. make sure it has a constructor with a signature of type File.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Thank you, however that is the cause of the problem. See the snippet below, it does have a constructor with a File parameter. It works as I use it to construct the the object from within the class's own main perfectly. I am non-plused. I believe everything is as it should be, and it does not work.

package samplemp3;

import java.io.*;
import java.util.*;
import javazoom.jl.decoder.*;
import samplemp3.Header;

/**
* Reads MP3 file into memory and allows to cut a piece of the MP3 into the output file
*/
public class SimpleMP3Read {
public int counter;
private int countFrames;
private float ms_frame;
private int header_pos;
private float length;
private float[] timeMarks;
private byte[][] framesContent;
private byte[] id3v2;

/**
* Constructor
*
* @param mp3 Input MP3 file
* @throws IOException
* @throws BitstreamException
*/
public SimpleMP3Read(File mp3) throws IOException, BitstreamException {
counter = 0;
System.out.println("in the SimpleMP3Read constructor");
loadFile(mp3);
}
[code eliminated]


Originally posted by alan do:
you did not post your SimpleMP3Read.java. make sure it has a constructor with a signature of type File.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
hm...do you have the stack trace of the error?
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Thank you. See below. I cant understand the line:
java.lang.NoClassDefFoundError: samplemp3/SimpleMP3Read
at samplemp3.actions.SampleMP3Action.execute(SampleMP3Action.java:46)
which of course is the exact line where I call the constructor from within the Action.

exception javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
root cause java.lang.NoClassDefFoundError: samplemp3/SimpleMP3Read
at samplemp3.actions.SampleMP3Action.execute(SampleMP3Action.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


Originally posted by alan do:
hm...do you have the stack trace of the error?


alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
ah, that makes sense now. the .java class was not properly compiled into a .class into the correct path. this is an environment issue that has several causes. see http://www.jguru.com/faq/view.jsp?EID=455768 or do more searches to solve the NoClassDefFoundError.
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Thanks
I dont quite understand your interpretation, but will research it. Can you tell me how you inferred that from the stack trace? I dont see anything that indicated a compiler problem? Just trying to understand it more than superficially. Again Thanks.

Originally posted by alan do:
ah, that makes sense now. the .java class was not properly compiled into a .class into the correct path. this is an environment issue that has several causes. see http://www.jguru.com/faq/view.jsp?EID=455768 or do more searches to solve the NoClassDefFoundError.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
it's a common classpath setting issue: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NoClassDefFoundError.html.as for reading the stack trace, i generally ignore everything except for the stuff near the last (top most) lines. search for the exception (on google) and find the result from java.sun.com to see what the probable causes are.
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Thank you for the detail. What I find incredulous is I am using Borland JB05 SP4 and it was working perfectly all morning/afternoon, except for the error cited. NOW it is giving me the pretty lethal:
java.lang.ClassNotFoundException: org.apache.catalina.core.StandardServer
which I know is in the obvious package. I dont know if this is comming from TC, struts or jstl. But I never had to be concerned about it before. I didnt do any file deletion or environment variable changes. How could it possibly have "broken all of a sudden"? I know it comes down to a version of RTFM/learning curve. I have the same IDE working on another PC and I will merrily waste my time bouncing back and forth. I will also copy over the project to that PC and see if it runs. If you can provide an additional "heads up" thanks. None the less, thanks you for the advice up to now; it was valuable, edifying and efficient.
Originally posted by alan do:
it's a common classpath setting issue: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NoClassDefFoundError.html.as for reading the stack trace, i generally ignore everything except for the stuff near the last (top most) lines. search for the exception (on google) and find the result from java.sun.com to see what the probable causes are.
 
 
subject: constructor problems