BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-09-2005, 09:11 PM   #1 (permalink)
New Member
 
Join Date: Jun 2005
Model: 7520
Carrier: Sprint
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile onFocus problem

Please Login to Remove!

Hi,
I am new the both Java and Blackberry, and am trying learn by stepping through the sample code. I am using the code from the knowledge base document, DB-00147. I tried to override the onFocus method using the following code
protected void onFocus (int direction){
int index = listField.getSelectedIndex();
blackBerryContact = (BlackBerryContact)blackBerryContacts.elementAt(in dex);
};
I am able to step through the code, and retrieve the first contact, but when I exit the method, I receive the following error” “Uncaught exception thrown. Null Pointer Exception. I went through the API’s trying to find what exceptions are thrown by ListField object, but I could not find any. I was hoping someone call me what is going wrong.

Thanks,
Tom
Offline  
Old 08-10-2005, 08:29 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Dec 2004
Location: in a house...
Model: lots
Carrier: Rogers
Posts: 1,148
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would imagine that,
Code:
blackBerryContact = (BlackBerryContact)blackBerryContacts.elementAt(index);
is returning a null. try adding something like this...
Code:
if ((BlackBerryContact)blackBerryContacts.elementAt(index)==null)
    { 
        System.err.println("Element is null");
        return;
    }
else
    {  
        blackBerryContact = (BlackBerryContact)blackBerryContacts.elementAt(index); 
    }
If you can post a little more code around what you have already posted so we can see where you are trying to override the method it may be more helpful as well.

cd.
Offline  
Old 08-10-2005, 08:30 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Dec 2004
Location: in a house...
Model: lots
Carrier: Rogers
Posts: 1,148
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kinda weird how spaces keep getting added to the code even though they are not there when we make the post. I have noticed this before.

cd.
Offline  
Old 08-10-2005, 06:26 PM   #4 (permalink)
New Member
 
Join Date: Jun 2005
Model: 7520
Carrier: Sprint
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for responding. I tried your code, but I still got the error. I am not familiar enough with the Blackberry IDE or the Blackberry API's to do any heavy debugging. I have included the code in the attached zip file. I thought it would be easier for you to find the problem. I hope you do not mind.

Thank you very much,
Tom

Last edited by tommcf : 08-13-2005 at 03:54 PM.
Offline  
Old 08-11-2005, 09:13 PM   #5 (permalink)
New Member
 
Join Date: Jun 2005
Model: 7520
Carrier: Sprint
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please disregard my last post. I figured it out.
Thanks
Offline  
Old 08-13-2005, 01:00 PM   #6 (permalink)
New Member
 
Join Date: Aug 2005
Model: 7290
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about sharing the solution to your problem?

Thanks
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.