BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-10-2008, 01:08 PM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8011
PIN: N/A
Carrier: vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom EditField

Please Login to Remove!

Hi all, I'm new to Blackberry development. I try to write a custom field, but it throws exception. Can someone kindly point out why?

The requirement is the cursor won't move anymore (fixed at one point) once user key in more than N chars.

Code:
class FixedCursorField extends EditField{
private int fixedCursorPosition;
	
	public FixedCursorField(String label, String initialValue, int fixedCursorPosition) {
		super(label, initialValue);
		this.fixedCursorPosition = fixedCursorPosition;
	}
	
	protected void update(int delta) {
		super.update(delta);
		if (getText().length()>=fixedCursorPosition){
			setCursorPosition(fixedCursorPosition);
		}
	}
	
}
Thanks,
Peter
Offline  
Old 11-10-2008, 01:18 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 17
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can help you with this... but first 2 questions.

1) What type of exception is it throwing?

2) Have you tried using EditField.setMaxSize(int size) instead of overriding the update(int delta) method?
Offline  
Old 11-10-2008, 01:40 PM   #3 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8011
PIN: N/A
Carrier: vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

1) It throws 'Error', JVM Error 104
2) The requirment is to allow users to enter any text with no length restriction. The cursor needs to stop at some fixed location once the input text's length reach to 'N'. Note that users can key in the text even the length is > 'N'

Thanks
Peter
Offline  
Old 11-10-2008, 01:52 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 17
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Any chance you could look into your device's event log and check what type of exception is being thrown? (JVM Error 104 means that there is an uncaught exception)

My guess is that
Code:
setCursorPosition(fixedCursorPosition);
is throwing an uncaught ArrayIndexOutOfBoundsException ... you should probably be placing the cursor at (fixedCursorPosition-1) since your positions available in the field will be from 0 to (n-1), where 'n' is the length of your text
Offline  
Old 11-10-2008, 02:14 PM   #5 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8011
PIN: N/A
Carrier: vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, the problem is from 'setCursorPosition'. I try to debug in Eclipse and I get

Code:
Error
No detail message
net_rim_cldc-9
 TextField
 getCaretRect
 0x48A8
net_rim_cldc-9
 TextField
 getFocusRect
 0x52B7
It doesn't really help
Offline  
Old 11-10-2008, 02:42 PM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 17
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you try changing to setCursorPosition(fixedCursorPosition-1);?
Offline  
Old 11-10-2008, 04:19 PM   #7 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8011
PIN: N/A
Carrier: vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm afriad it doesn't work with 'fixedCursorPosition-1'
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.