this is the code:
static void output () {
StringBuffer sb = new StringBuffer();
String recall, accuracy;
sb.append( "\n\rcycle: " + bpn.getLearningCycle() + "\n\n\r input: target: output: error:\n\r" );
System.out.print(bpn.getNumberOfPatterns());
for ( int x=0; x<bpn.getNumberOfPatterns(); x++ )
sb.append( " " + bpn.getInputPattern(x) + " " + bpn.getTargetPattern(x) + " " + bpn.getOutputPattern(x) + " " + bpn.getPatternError(x) + "\n\r" );
System.out.println( sb );
}
public static void main ( String[] args ) {
System.out.println( "\n\n\rDEMO OF A BACKPROPAGATION NET\n\r" );
if ( args.length == 0 ) {
System.out.println( "Missing argument --- Usage: java BPN <display step>" );
System.exit( 0 );
}
else {
BackpropagationNet bpn = (new BPN()).new BackpropagationNet();
System.out.print( "Reading conversion file ..." );
bpn.readConversionFile( "ascii2bin.cnv" ); // 1 ascii value -> 6 binary values
System.out.println( "OK" );
// some optional method calls
bpn.setLearningRate( 0.25 );
bpn.setMinimumError( 0.0005 );
bpn.setAccuracy( 0.2 );
bpn.setMaxLearningCycles( -1 ); // -1 = no maximum cycle
bpn.setDisplayStep( Integer.parseInt( args[0] ) ); // get the argument
System.out.print( "\n\rallright, let's learn...\n\r" );
bpn.resetTime();
while ( !bpn.finishedLearning() ) { // while the net learns
bpn.learn(); // perform one learning step
if ( bpn.displayNow() ) output(); // display the current results
}
output();
System.out.println( "\n\rFINISHED." );
}
}
i can compile this code with no errors, but when i execute, i get this message:
Exception in thread "main" java.lang.NullPointerException in the output() function where sb.append appears.
I dont understand why is the NullPointer when StringBuffer can be modified

New Topic/Question
Reply



MultiQuote








|