Can you have a look at my code please, where am i going wrong?
Compiles fine but i get a nullPointerException
in the setLayerOne() method and the setInputs() method
the error seems to point to the Neuron[][] network
but i thought it should be ok as i initilised the pointer as static
the Neuron class is compiled and contains both these methods.
also, is this bad design to make all my varibles static like this
thanks for the help
Tim
import java.io.*;
publicclass Guesser{
staticchar[] user =newchar[100];
staticint guess_no = 1;
staticint noOfLayers;
static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
static Neuron[][] network;
staticint[] layers;
publicstaticvoid main(String args[])
throws IOException
{
guesserNetwork();
///now for the guessing bit
int guess_no = 0;
char guess;
//char dummy;
//BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
char[] user =newchar[100];
while (guess_no<10){
System.out.println("Please think of Heads (H) or Tails (T) then press enter.");
if (guess_no == 1)
{
guess ='H';
}
elseif ( user[guess_no] =='H' )
{
guess ='T';
}
else
{
guess ='H';
}
// now we tell the user what our guess was,
char dummy;
dummy = (char) br.read();// wait for the return key pressed
System.out.println(guess);
// Find out what the user was thinking of
// and force the user to H or T
user[guess_no] = (char) br.read();
if (user[guess_no] =='h')
{user[guess_no] ='H';}//this does not work i dont know why
elseif (user[guess_no] =='t')
{user[guess_no] ='T';}
dummy = (char) br.read();// clear the stream for the return key press
while ( user[guess_no] !='H' && user[guess_no] !='T')
{
System.out.println("You must enter H or T");
user[guess_no] = (char) br.read();
}
setLayerOne();//////HERES WHERE I GET NULLPOINTER EXCEPTION
guess_no++;
}
while (guess_no<100){
//call update method
//print output of last node
network[0][guess_no].inputGuess(guess_no);
guess_no++;
}
}
staticvoid setLayerOne()////I GET NULLPOINTER EXCEPTION
{
network[0][guess_no].inputGuess(guess_no);// sets the first layer neurons
}
staticvoid setInputs ()
{
for (int i = 1; i < noOfLayers; i++){
for(int j=0; j < layers[i]; j++){
network[i][j].updateInput(i, network[i-1], network[i-1].length);//sets the other neurons
}
}
}
staticvoid guesserNetwork()
{
int noOfNeurons[] ={10,1,1};
int nodes = 0;
noOfLayers = 3;
int[] layers =newint[noOfLayers];
for (int i =0; i < noOfLayers; i++)
{
layers[i] = noOfNeurons[i];
System.out.println("layer " + (i + 1) +" has " + noOfNeurons[i] +" neurons");
nodes += noOfNeurons[i];
}
System.out.println("total no of nodes = " + nodes);
System.out.println("building network...");
//make (noOfLayers)arrays of arrays
Neuron[][] network =new Neuron[noOfLayers][];
for (int i=0; i < noOfLayers; i++)
{
//for each layer make the desired number of rows(of neurons)
int rows = layers[i];
network[i] =new Neuron[rows];
//instinate neuron objects one by one
for (int j=0; j < layers[i]; j++)
{
if (i==0)
{
network[i][j] =new Neuron(noOfLayers, i, j, rows, 1, user[j]);
}
else
{
boolean isFirstLayer =false;
network[i][j] =new Neuron(noOfLayers, i, j, rows, layers[i-1], network[i-1]);
}
}
}
}
}

