Please help me to solve the error:

coordinates2T[a]=-3.7830557977332173
coordinates2T[a]=-3.7830557977332173
coordinates2T[a]=-3.7830557977332173
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at KateAug24.main(KateAug24.java:137)
Press any key to continue...

Thanks is adv!


import java.io.*;
import java.util.*;
import java.text.*;




public class KateAug24{
	
   	private static StringBuffer buffer;
   	private static BufferedReader input1=null;
   	
   
   	public static String [] arrayM1 = new String [5000];
   	public static String [] arrayM2 = new String [5000];
   	public static Double [][] coordinates1 = new Double [10000][100];
   	public static double [][] coordinates2 = new double [10000][100];
   	public static double [][] coordinates2T = new double [5000][100];
   	public static double [] Translate = new double [10]; 
    
   	public static double [][] coordinatesDiff = new double [10000][300]; 
  
   	static DecimalFormat fmt= new DecimalFormat("0.000"); //3 D.P
	
	public static void main(String args[]) {
	 	
	 	
	int i=0,j=0;	
   	String text1;
   	String text2;
   	double X=0;
   	double Y=0;
   	double Z=0;

    try{


    FileInputStream fstream1 = new FileInputStream("D:\\project1\\exp\\proteins\\1A6G.pdb.txt");
    FileInputStream fstream2 = new FileInputStream("D:\\project1\\exp\\proteins\\1A6K.pdb.txt");
    DataInputStream in1 = new DataInputStream(fstream1); // Get the object of DataInputStream
    DataInputStream in2 = new DataInputStream(fstream2); // Get the object of DataInputStream
    BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
    BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));

    while ((text1 = br1.readLine()) != null)   {  //Read File Line By Line

        if(text1.trim().startsWith("ATOM")) {
        	StringTokenizer s1 = new StringTokenizer(text1," ");

         	int counter1=0;
          	String line1="";

          	while(s1.hasMoreTokens()) {

				String ss1 = s1.nextToken();
		    	counter1++;

		    	if(counter1 == 3){
		    		line1 += ss1;
		    		arrayM1[i] = ss1;
		    	}
		    }

    		coordinates1[i][0]= Double.parseDouble(text1.substring(30,38));//X
			coordinates1[i][1]= Double.parseDouble(text1.substring(38,46));//Y
			coordinates1[i][2]= Double.parseDouble(text1.substring(46,56));//Z



			i+=1;
		}//end of if


	} //end of while.
 
		
			
			
			
	i=0;

	while ((text2 = br2.readLine()) != null)   {  //Read File Line By Line

        if(text2.trim().startsWith("ATOM")) {
        	StringTokenizer s2 = new StringTokenizer(text2," ");

         	int counter2=0;
          	String line2="";

        	while(s2.hasMoreTokens()) {

				String ss2 = s2.nextToken();
		    	counter2++;

		    	if(counter2 == 3){
		    		line2 += ss2;
		    		arrayM2[i] = ss2;
		    	}
			}

    		coordinates2[i][0]= Double.parseDouble(text2.substring(30,38));//X
			coordinates2[i][1]= Double.parseDouble(text2.substring(38,46));//Y
			coordinates2[i][2]= Double.parseDouble(text2.substring(46,56));//Z
		
			 i+=1;	
				
		
		 }//end of if


	} //end of while.

			}//end of try



			catch( IOException e) {
				e.printStackTrace();
				}//end of catch

//------------------------------------------------------------------------------				
				
				
				
				for(int a=0; a<coordinates1.length; a++) {
       for(int b=0; b<coordinates1[a].length; b++) { 
          for(int c=0; c<coordinates1[b].length; c++){
         
      
         
            X = coordinates1[1][0]/coordinates2[1][0];
			Y = coordinates1[1][1]/coordinates2[1][1];
			Z = coordinates1[1][2]/coordinates2[1][2];
         
         double [][] Translation1={ {X,0.0,0.0}, {0.0,Y,0.0}, {0.0,0.0,Z} };
         
         coordinates2T[a][b]+= coordinates2[a][c]*Translation1[c][b];
         
             if( coordinates1[a][b]!= null)
System.out.println("coordinates2T[a][b]="+Translation1[c][b]);
 //Print out the whole array
         	
    	
}
}
}
	}// end of main
	}
Member Avatar for coil

Your for-loop is making a, b, or c a number outside of an array length.

I don't see the declaration immediately, but let me guess. One of the dimensions of your array is 3, right? So when you try to index position 3, you walk off the edge. Is that it?

Hi guys, perhaps you could refer to the continuation.. I'm not too sure either.. I just learned Java

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.