The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Passing an array to the constructor!

I implemented RC4 cryptography algorithm using Java but I still don't know why it doesn't work when I try to pass an array from main method to the constructor! How can I make it works?
Thank you in advance

Re: Passing an array to the constructor!

You've commented to initialize S[] and T[], but do you actually initialize them anywhere? An array needs to be initialized with a length.
Also, when asking a question, make sure to tell us what is going wrong. "It doesn't work" is not a helpful statement for us. Is the output different than you expect, and how is it different? Are you getting exceptions or errors, and what type of exceptions and errors?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: Passing an array to the constructor!

Oh! I'm sorry for that! I'm a new user here! I will be clear

I got this error:
-----------------------------------------------------------------
Exception in thread "main" java.lang.NullPointerException
at rc4.generator.RC4_Generator.<init>(RC4_Generator.j ava:18)
at rc4.generator.RC4_Generator.main(RC4_Generator.jav a:62)
----------------------------------------------------------------
Do you see guys why? I try to understand it but I couldn't!

Re: Passing an array to the constructor!

I would guess because S[] and T[] have not been initialized, but you attempt to add values to them.
You need to initialize them beforehand in your constructor like this:

S =newint[256];// 256 is the size of the array, you can change this to whatever length seems appropriate
T =newint[256];

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/