Hi everyone,

Could any one help me with this code, please. I do not know why it's giving this kind of error. The code, which is a part of a lager program, is as given below. I will try explaining what each variables represent.

   public void backwardComputation(int m, Double desiredOutput[][])
   {
         int i, j = 0;

      deltaOutput[j] = (1 * (desiredOutput[m][j] - targetOutputA[j]));
      System.out.println(deltaOutput[j]);

      for(i = 0; i < hiddenNeurons; i++)
         for(j = 0; j < outputNeurons; j++)
         deltaHidden[i]=((hiddenA[i]*(1 - hiddenA[i]))*(deltaOutput[j] * outputToHiddenWeight[i][j]));
}

Let us say the variables outputNeurons and hiddenNeurons are given as 1 and 3 respectively, but each time i attempt to store ((hiddenA[i](1 - hiddenA[i]))(deltaOutput[j] * outputToHiddenWeight[i][j])); into the array deltaHidden[i], it gives an error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundExceptions: 1" and I have checked that the array deltaHidden[] have enough spaces, and that all other arrays in the equation work out fine. Can you help looking into this please?

Recommended Answers

All 2 Replies

No, not really, because you only posted a fragment of code that cannot be run and your indexes are going to vary at runtime. It's very simple for you to find the problem on your own though. Check your array sizes before you access them. Obviously one of those arrays only has a single element and you are trying to access a second.

You are right indeed. I took a second look at all the arrays in that piece of code, and I found out that there is one which the length is supposed to be more than one, and which I have mistakenly made to be one. Thank you very much for your advice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.