NoClassDefFound puzzle
NoClassDefFound is my least favourite error message. This one has me
stumped. I have been very sick the last few days and my brain in not
yet fully engaged, so I hope it is something simple.
I compile this fine, but when I run it, it says class
com.mindprod.example.TestProgessFilter is not defined.
The program seems too simple to have a NoClassDefFound problem.
package com.mindprod.example;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* @author Roedy Green, Canadian Mind Products
* @version 1.0, 2007-08-03 Created with IntelliJ IDEA.
*/
public class TestProgessFilter extends FilterInputStream {
/**
* tracks how many bytes we have read so far
*/
long progress;
// -------------------------- PUBLIC INSTANCE METHODS
--------------------------
/**
* Constructor
*
* @param in input stream to progress monitor
*/
public TestProgessFilter( InputStream in )
{
super( in );
}
/**
* Reads the next byte of data from this input stream.
*/
public int read() throws IOException
{
int ret = super.read();
progress++;
reportProgress();
return ret;
}
/**
* Reads up to byte.length bytes of data from this input stream
into an
* array of bytes.
*/
public int read( byte[] b ) throws IOException
{
int ret = super.read( b );
progress += b.length;
reportProgress();
return ret;
}
/**
* Reads up to len bytes of data from this input stream into an
array of
* bytes.
*/
public int read( byte[] b, int off, int len ) throws IOException
{
int ret = super.read( b, off, len );
progress += len;
reportProgress();
return ret;
}
/**
* Skips over and discards n bytes of data from this input stream.
*
*/
public long skip( long n ) throws IOException
{
long ret = super.skip( n );
progress += n;
reportProgress();
return ret;
}
// -------------------------- OTHER METHODS
--------------------------
/**
* report the progress to the user
*/
private void reportProgress()
{
// this is a dummy routine. A real version would send an event
// to a progress meter.
System.out.println( progress );
}
// --------------------------- main() method
---------------------------
/**
* test driver
*
* @param args arg[0] is UTF-8 filename to read
*/
public static void main( String args[] )
{
try
{
// O P E N
FileInputStream fis = new FileInputStream( new File( args[
0 ] ) );
TestProgessFilter tpfis = new TestProgessFilter( fis );
InputStreamReader eisr = new InputStreamReader( tpfis,
"UTF-8" );
BufferedReader br = new BufferedReader( eisr, 400/*
buffsize */ );
// R E A D
while ( true )
{
if ( br.readLine() == null )
{
// line == null means EOF
break;
}
}
// C L O S E
br.close();
}
catch ( Exception e )
{
System.err.println( e );
e.printStackTrace( System.err );
}
}
}
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com