• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an exception

 
kevin chang
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public DataInfo[] getAllData() throws NBFException{
ArrayList aList=new ArrayList(1);
DataInfo cr=null;
DataInfo[] newdata;
try{ Data link=obtainConnection();
for(int i=1;i<=link.getRecordCount();i++){
cr=link.getRecord(i);
aList.add(cr);
}
if(aList.size() >0)
{newdata=(DataInfo[])aList.toArray();}
else{newdata=null;}
return newdata;
}catch(Exception e){e.printStackTrace();
throw new NBFException("NBFMoodelDbImpl.getAllData\n"+e);}
}
In these code, always stop at"newdata=(DataInfo[])alist.toArray();} and throw Exception,it never touchs the "return", i used watch and see nothing, what's wrong on earth?
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess it is probably casting problem. But I don't think you need an ArrayList here since you know your array size.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

newdata=(DataInfo[])alist.toArray();

It should be:
newdata=(DataInfo[])alist.toArray(new DataInfo[alist.size()]);
On a side note, I strongly recommend that you follow Java Naming Conventions, -- things like "aList", "cr", and "newdata" will not pass. And I don't even want to mention your "NBFException", -- does it stand for "Night Before Flight Exception"?
Eugene.
[ March 26, 2003: Message edited by: Eugene Kononov ]
 
kevin chang
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

thanks first, I do follow this Naming Conventions. but I really don't what's wrong here, I'd appreciate if u could make it in detail!
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,
Your answer, in principle, is in the following bit of code. Why don't you explain to me why it works .
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thanks first, I do follow this Naming Conventions.

Not really:
First, the variable name must be meaningful. You variable "aList" is as meaningful as variable that is named aVariable. Same goes for your variable "cr". What the heck is it? Secondly, the convention is to capitalize the first letter of the internal word in the variable. So, your "newdata" must be "newData". Finally your "NBFException" should be FBNException", unless your NBF abbreviation stands for something else (what is it?).
Eugene.
 
kevin chang
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot , now i do follow your instruction, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic