null pointer exception

I am catching #@#%$ with this runtime null pointer exception. I know where it is but for some reason, I can't get rid of it no matter what i do. Help!!!

here is my entire code:

import java.util.*;

import java.io.*;

publicclass Tubeimplements Energy{

public Sequence[] seqArray =new Sequence[2];

public Sequence[] aStrand =new Sequence[20];

public Sequence test=new Sequence();

publicint numSeq = 0;

publicint testLength = 0;

publicint number =0;

publicint length = 0;

public Random generator =new Random();

public String[] gene ={"A","C","G","T"};

int d = 0;

/** Adds a sequence and copies it with doubleArray() */

publicvoid addSequence(Sequence A){

if(numSeq >= seqArray.length)

seqArray = doubleArray();

seqArray[numSeq++] = A;

}

/** Sets a TestLength */

publicvoid setTestLength(int i){

this.testLength = i;

}

/** Gets the sequence Array */

public Sequence[] getSeqArray(){

return this.seqArray;

}

/** Gets the number of the sequence */

publicint getNumSeq(){

return this.numSeq;

}

/** Tests to see if sequences are the same */

publicboolean isDuplex(Sequence A, Sequence B){

int iter = A.getSequence().length() - this.testLength + 1;

String testWMer;

String Astring = A.getSequence();

String Bstring = B.getSequence();

for(int i = 0; i < iter; i++){

testWMer = Astring.substring(i, i + this.testLength);

if(Bstring.indexOf(testWMer) != -1)

returntrue;

}

returnfalse;

}

/** copies array */

private Sequence[] doubleArray(){

Sequence[] newArray =new Sequence[2*this.seqArray.length];

System.arraycopy(this.seqArray, 0, newArray, 0, numSeq);

return newArray;

}

/** creates random sequences */

public Sequence[] randomSequence(int number,int length)

{

Random generator =new Random();

test.sequence ="";

for(int i = 0; i < number; i++){// number of sequences to be made

aStrand[i].sequence = test.sequence;// <--here is where i get the null pointer exception

for(int j = 0; j < length; j++){//length of sequences to be made;

int d = generator.nextInt(4);

aStrand[i].sequence += gene[d];

}

aStrand[i].sequence += gene[d];

}

return aStrand;

}

}

[5450 byte] By [cblake80] at [2007-9-30 22:10:32]
# 1
aStrand is null, so attempting to access its sequence member causes the error.You declare the aStrand array, but you don't initialize it, so all of its entries are null.
DrClap at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 2
Sorry, I got caught by that trap.aStrand[i] is null, so attempting to access its sequence member causes the error.You declare the aStrand array, but you don't initialize it, so all of its entries are null.
DrClap at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 3
I have tried initializing it, but i keep getting the same error.How would you do it?
cblake80 at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 4
Hmm, and how do you suppose "I get the same error" will help people solve your problem?
The-Sue at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 5
Hi Sue! Long time no see...
CeciNEstPasUnProgrammeur at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 6

> I have tried initializing it, but i keep getting the

> same error.

And what did you do to set up the array so that its entries were something other than null?

> How would you do it?

I would set each of the entries in the array to something other than null. In your case perhaps a new Sequence object would work. Up to you though.

DrClap at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 7

Ever thought about writing a proper constructor?

public Tube()

{

this.seqArray = new Sequence[2];

// 2 is a magic number, but it's your funeral

for (int k = 0; k < 2; ++k)

this.seqArray[k] = new Sequence();

this.aStrand = new Sequence[20];

// same with 20

for (int k = 0; k < 20; ++k)

this.aStrand = new Sequence();

}

Now none of your array elements are null.

%

duffymo at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...
# 8
Forgot the [k] in the second loop, but you get the idea.%
duffymo at 2007-7-7 11:23:39 > top of Java-index,Security,Event Handling...