Wednesday, October 04, 2006

java.util.NoSuchElementException

java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)


Description from API:
The string tokenizer class allows an application to break a string into tokens.

The tokenization method is much simpler than the one used by the StreamTokenizer class.
The StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments. http://java.sun.com/j2se/1.5.0/docs/api/index.html

I got this problem while I was trying to deploy the source code at development server.After that I found out that the sql statement only produce 5 value but inside looping it request for 6 values,that's why NOSUCHELEMENT.So make sure that it's match first,what you ask is what you get.And then lastly, I found out
that one of programmer forgot to commit her coding!!

Solution :Make sure there are matching values.

Vector vt = new Vector();
if(iStudentId != 0) {
vt = Cocurriculum.getCocuApplyList(schoolID,iStudentId);
}
int i = 0;
if(vt.size() > 0) {
i = 0;
}

for (Enumeration e = vt.elements(); e.hasMoreElements(); ) 
{//all return 6 values(if sql is mismatch with this, can produce error)
String strOptionRow = new String ((String) e.nextElement());
StringTokenizer stkTokenizer = new StringTokenizer(strOptionRow, ";");
String sApplyId = stkTokenizer.nextToken();
String sCocuType = stkTokenizer.nextToken();
String sCocuName = stkTokenizer.nextToken();
String sApplyDate = stkTokenizer.nextToken();
String sStatus = stkTokenizer.nextToken();
String sRemark = stkTokenizer.nextToken();


public static Vector getCocuApplyList(int schoolID,int iStudentId)//example of 6 values
{ 
String strQuery = "select * from cocu_program p, cocu_apply a where a.student = ? and a.program = p.program_id"; 
while (rsReturn.next())
{
//it's return 6 values
vt.addElement(iApplyId + ";" + iCocuType + ";" + sName + ";" + dApplyDate + ";" + sStatus + ";" + sRemark); 
}
return vt;
} 

Saturday, September 30, 2006

Hai allllll!!! I am again.
Objective of this new blog is where I can put all solution in a site. So I don’t have to refer back to my unreadable handwriting notes whenever I got problem in Java, programming, computer, network or anything about machine.


For your information, I write all the solutions in a book, I already got more than 5 books that mixed up solution and problem and then it become problem to me.
Not enough space to keep it and my desk look like hell.

So better I use this technology to simplify my working way, and I hope I can share with other peoples. But please don’t believe my solution 100% because sometimes the solution is only apply to my situation and I am not hard core programmer to give the really best solution. My solution sometimes maybe does not work at yours but who care? My problem solved anyway. But If you got better solution, please let me know because I also computer-geek want to be. ;-)

Oh?! You asking me about the name of this blog? Unid and Machine! It’s cool what.When I was little I used to watch Mann and Machine series.It’s about a guy who named Mann that bored working with robots. He is cop that does not have work-partner from human, usually they gave him robot which after that he getting mad because of that. Then his boss give him, a woman robot(beautiful like human) named Eve Edison. So beautifulllllllll and that is the one of important reason I ‘m waiting for that series. Eve Edison really human alike, except she can’t eat. Her emotion is same like 7 years kid.

Ok done. It is not movie review site. Use Google and help yourself. See you next time. Papai