NoClassDefFound puzzle  
Author Message
Roedy Green





PostPosted: 2007-8-3 17:11:00 Top

java-programmer, 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
 
voorth





PostPosted: 2007-8-3 17:42:00 Top

java-programmer >> NoClassDefFound puzzle On Aug 3, 11:11 am, Roedy Green <email***@***.com>
wrote:
> 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.
>

The only thing I can see is the obvious mispeling in your class name.
Are you sure the client code is not looking for a
TestP[r]ogressFilter?

Henk van Voorthuijsen

 
Roedy Green





PostPosted: 2007-8-3 18:08:00 Top

java-programmer >> NoClassDefFound puzzle On Fri, 03 Aug 2007 02:42:24 -0700, voorth <email***@***.com> wrote,
quoted or indirectly quoted someone who said :

>The only thing I can see is the obvious mispeling in your class name.
>Are you sure the client code is not looking for a
>TestP[r]ogressFilter?

That's it! I used the proper spelling when I tried to invoke the
class. I suspected that but much as I stared it, I could not see the
typo. I even copy pasted it to all instances internally in the file
to make sure they were all the same -- identically wrong.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com