I got the error for possibleseq array . The error is java.lang.NullPointerException. As java doesn't support pointer, when want to use dynamic array, how I can use. The array length cannot know exactly . It depends on the possible subsequences. So, Do I count the possible sequences in advance and only after getting that, I create possible seq array with new operator? Is there other ways without counting array length in advance? Thanks in advance.

private void DiscoverSeqPattern(String seq, int repnum)
		String[] possibleseq = null;
		String temp;
		int i=0,j;

		//seq = "title author author editor";
		//repnum = 2;
		//subseq = {title,author,author,editor"};

		String[] subseq = seq.split("\\s");			//split seq into subseq with space

		while ((i<subseq.length) && ((i+repnum-1)<subseq.length))
			temp = subseq[i];

			for (j=i+1;j<i+repnum;j++)
				temp = temp.concat(" ").concat(subseq[j]);
			possibleseq[i] = temp;


Recommended Answers

All 3 Replies

You could use an ArrayList instead. It has dynamic lengths.



You received a NullPointerException because the array possibleseq is always null and you end up using it in your code.

The best solution is to create an ArrayList by writing

[B]ArrayList [/B]possibleseq= new [B]ArrayList[/B]();

then add your strings into it by writing:


Then to get the 11th item from the ArrayList write:

//this line gets the 11th object and casts it into a String
[B]String [/B]obj = ([B]String[/B])(possibleseq.get(10));

For more help, www.NeedProgrammingHelp.com


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.