Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2008, 02:17 AM   PM User | #1
PoRco
New to the CF scene

 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
PoRco is an unknown quantity at this point
Array Index Out of Bounds Exception !

I re coded it with different names for my array and it worked, but when I cross check the two, I can't spot the error..
Code:
java.lang.ArrayIndexOutOfBoundsException: 25
	at A3Q2.main(A3Q2.java:67)[/I]
Can you guys please help me? I tried everything.

The program is supposed to code an input of a word into an array

Code:
class A3Q2 
{
    public static void main (String[] args)
    {

        char original[];  // Original Alphabet
       
       original = new char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
        
        char  code[]; // Code corresponding to Alphabet
        code = new char [] {'t','m','e','s','f','k','j','a','x','n','o','v','u','l','c','h','z','g','y','b','w','p','d','r','i','q'};
        int n = 0;
        char [] wa  = new char[n];
        int C;
        int I;
        int C2;
        int I2;
        int p;
        
       // READ IN GIVENS  - use the class ITI1120

     System.out.println(" Please input a word");
                        
        wa = ITI1120.readCharLine();
          

n = wa.length;

        char [] wa2 = new char[n];
        char [] wa3 = new char[n];
        
     
        
        // BODY

    
  C = 0;
  C2 = 0;
  
  
        {    
        while (C < n)
        {
          I = 0;
          while ( I <= 25)
          {
            if ( wa[C] == original[I])
            {
              wa2[C] = code[I];
            
            }
            
            I = I + 1;
            
          }
          C =  C + 1;
        }
        }
         
       p =0;
    while (p < n)
    { 
      System.out.println ( wa2[p] );
      p = p+1;
      
    }
    }
}
PoRco is offline   Reply With Quote
Old 10-20-2008, 07:30 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'm too tired to debug it, but it looks like its a simple index in using 'i'. You don't appear to have an 'i', though you do have an 'I'.
Looks like that's here:
Code:
if ( wa[C] == original[i])
{
    wa2[C] = code[i];
            
}
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 10-20-2008, 02:04 PM   PM User | #3
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Yeah he's right on your code. I'm not even sure how that compiled in order to get the ArrayIndexOutOfBounds Exception.

Undoubtedly a Silly IDE is doing the work for you!
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:26 PM.


Advertisement
Log in to turn off these ads.