Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
madiha
Posts: 107
Registered: ‎05-26-2011
My Device: Torch

OutOfMemoryError

[ Edited ]

Hi,

 

I have build an app ... after an hour of usage it makes the handset slow..

It is a background app it doenotexit and runs in bg.

I have seen that it is taking memory in MBs after an hour of usage it took 85 MBs. while other apps were just taking memory in KBs.

I have seen in the log

OutOFMemoryError due to Bitmap.getresoure methods ...

 I am using BB Bold 9780 device...

Can any one tell me why i am getting this error ??

 

Thanks

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: OutOfMemoryError

without the code: hard to say. i would closely look at all bitmaps, and if you maybe have references to unused items that deny GC access to them.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
madiha
Posts: 107
Registered: ‎05-26-2011
My Device: Torch

Re: OutOfMemoryError

[ Edited ]
Please use plain text.
Developer
madiha
Posts: 107
Registered: ‎05-26-2011
My Device: Torch

Re: OutOfMemoryError

public class CustomCheckBoxField extends CheckboxField { private ContactDTO _obj; String _text; Font _font = getFont().derive(Font.PLAIN, 7, Ui.UNITS_pt); Font _fontSmall = getFont().derive(Font.PLAIN, 6, Ui.UNITS_pt); boolean _paintBG = false; public Object get_obj() { return _obj; } public void set_obj(Object obj) { _obj = (ContactDTO) obj; } public CustomCheckBoxField(String label, boolean paintBG, boolean checked) { super(label, checked, Field.FOCUSABLE | Characters.BALLOT_X); _paintBG = paintBG; } public boolean isFocusable() { return true; } protected void onFocus(int direction) { super.onFocus(direction); invalidate(); } protected void onUnfocus() { super.onUnfocus(); invalidate(); } protected void paint(Graphics graphics) { // super.paint(graphics); graphics.setFont(_font); if (getChecked()) { graphics.drawBitmap(5, getPreferredHeight() - Constants._check.getHeight() >> 1, Constants._check .getWidth(), Constants._check.getHeight(), Constants._check, 0, 0); } else { graphics.drawBitmap(5, getPreferredHeight() - Constants._uncheck.getHeight() >> 1, Constants._uncheck .getWidth(), Constants._uncheck.getHeight(), Constants._uncheck, 0, 0); } graphics.setColor(Color.BLACK); graphics .drawText(getLabel(), Constants._check.getWidth() + 15, getPreferredHeight() - (graphics.getFont().getHeight() * 2) >> 1); graphics.setFont(_fontSmall); graphics .drawText(_obj.get_title(), Constants._check.getWidth() + 15, (getPreferredHeight() - (graphics.getFont().getHeight()) >> 1) + 10); if (isFocus()) { graphics.setColor(0xFFFFFF); } else graphics.setColor(Color.GRAY); } protected void layout(int width, int height) { // TODO Auto-generated method stub super.layout(width, height); setExtent(getPreferredWidth(), getPreferredHeight()); } public int getPreferredHeight() { // TODO Auto-generated method stub return Constants._bg.getHeight(); } public int getPreferredWidth() { // TODO Auto-generated method stub return Constants._bg.getWidth(); } protected void paintBackground(Graphics graphics) { super.paintBackground(graphics); if (_paintBG) graphics.drawBitmap(0, 0, Constants._bg.getWidth(), Constants._bg .getHeight(), Constants._bg, 0, 0); if (isFocus()) { graphics.drawBitmap(0, 0, Constants._hover.getWidth(), Constants._hover.getHeight(), Constants._hover, 0, 0); } graphics.setFont(_font); graphics.setColor(Color.BLACK); } protected void drawFocus(Graphics graphics, boolean on) { } } public class ContactsScreen extends MyMainScreen implements OutboundMessageListener, FieldChangeListener, PhoneListener { TopPanel topPanel = new TopPanel(1,this); MasterManager master; com.frt.bcm.ui.custom.Header header = new com.frt.bcm.ui.custom.Header( Manager.FOCUSABLE | Manager.USE_ALL_WIDTH, "", Bitmap .getBitmapResource("hedaer-contacts.png")); private boolean _multiSelected = false; private boolean init = true; private LoaderThread _loader; private Vector _groups; private Vector _ungroupedContacs; VerticalFieldManager body; private Hashtable _allContactsVtr; private Vector _contactBtnList; private boolean CustomGroupExists = false; private SimpleSortingVector sortedGroups; private Hashtable phoneCallsHash = new Hashtable(); private HistoryLog _phoneLog; private HistoryLog _smsLog; private HistoryLog _emailLog; private ContactDTO _currentContact; private Hashtable _emails; private Hashtable _smss; MessageConnection _mc; boolean _connected = false; public ContactsScreen() throws Exception { super(MainScreen.NO_SYSTEM_MENU_ITEMS); Phone.addPhoneListener(this); master = new MasterManager(Manager.NO_VERTICAL_SCROLL); master.add(header); master.add(topPanel); body = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLL_MASK | Manager.VERTICAL_SCROLLBAR | Manager.VERTICAL_SCROLLBAR_MASK) { protected void sublayout(int maxWidth, int maxHeight) { super.sublayout(maxWidth, maxHeight); setExtent(Constants.width, Constants.height - topPanel._height - header._height); } }; init(); // / make a list of contact button fields iterate through them and get // selected fields objects and then extract value from their objects UiApplication.getUiApplication().invokeLater(new LoaderThread()); body.setScrollListener(new ScrollChangeListener() { public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) { //invalidate(); master.invalidate(); } }); master.add(body); add(master); topPanel._contactsBtn.setFocus(); // if (!checkReconnect()) // UiApplication.getUiApplication().invokeLater( // new Thread(ContactsScreen.this)); } private void init() throws Exception { _groups = (Vector) GroupsDatastore.retrieveData(); _allContactsVtr = (Hashtable) ContactDataStore.retrieveData(); // getUngroupedContacts(); // Logger.getInstance().logInformationEvent(" groupd " + _groups); // Logger.getInstance().logInformationEvent( // "all contacts " + _allContactsVtr); boolean loadxml = false; if (_groups == null || _allContactsVtr == null) loadxml = true; else if (_groups.size() == 0) loadxml = true; if (_groups == null) throw new NetworkException("Network Exception"); else { sortGroups(); sortContacts(); } } private void sortGroups() { try { if (_groups != null) { sortedGroups = new SimpleSortingVector(); for (int i = 0; i < _groups.size(); i++) { GroupDTO grpDTO = (GroupDTO) _groups.elementAt(i); sortedGroups.addElement(grpDTO); Vector sortedIds; if (grpDTO.get_contactIds() != null) { sortedIds = getSortedContactEachGroup(grpDTO .get_contactIds(), true); grpDTO.set_contactIds(sortedIds); } } sortedGroups.setSortComparator(new Comparator() { public int compare(Object o1, Object o2) { String s1 = ((GroupDTO) o1).get_name(); String s2 = ((GroupDTO) o2).get_name(); return s1.toLowerCase().compareTo(s2.toLowerCase()); } public boolean equals(Object obj) { return false; } }); sortedGroups.setSort(true); _groups = sortedGroups; // _groups = sortedGroupsVector; } } catch (Exception e) { Logger.getInstance().logInformationEvent("das" + e.toString()); } } private class LoaderThread extends CustomThread { public void run() { synchronized (UiApplication.getUiApplication().getEventLock()) { // / try { body.deleteAll(); if (_ungroupedContacs != null && _ungroupedContacs.size() > 0) { body.add(new GroupBar("All Contacts")); _contactBtnList = new Vector(); } else if (_groups != null && _groups.size() > 0) { _contactBtnList = new Vector(); } int k = 0; if (_ungroupedContacs != null) for (int l = 0; l < _ungroupedContacs.size(); l++) { ContactDTO _contactDTO = (ContactDTO) _ungroupedContacs .elementAt(l);// _allContactsVtr // .get(_ungroupedContacs.elementAt(l)); CustomCheckBoxField _contactBtn = new CustomCheckBoxField( _contactDTO.get_fname() + " " + _contactDTO.get_lname(), (l % 2 == 0) ? false : true, false); _contactBtn.setChangeListener(ContactsScreen.this); _contactBtn.set_obj(_contactDTO); // _contactBtn.setFocusListener(ContactsScreen.this); _contactBtnList.addElement(_contactBtn); body.add(_contactBtn); } // Logger.getInstance().logInformationEvent( // "eee 2ddd " + _groups.size() + " " // + _allContactsVtr.size() + _contactBtnList); for (int i = 0; i < _groups.size(); i++) { GroupDTO _grpDTO = (GroupDTO) _groups.elementAt(i); GroupBar _grpHead = new GroupBar(_grpDTO.get_name()); // Logger.getInstance().logInformationEvent( // "fff" + _grpDTO.is_isCustom()); if (_grpDTO.is_isCustom()) CustomGroupExists = true; // Logger.getInstance().logInformationEvent( // "dsdf " + _grpDTO.get_contactIds()); body.add(_grpHead); if (_grpDTO.get_contactIds() != null) for (k = 0; k < _grpDTO.get_contactIds().size(); k++) { ContactDTO _contactDTO = (ContactDTO) _allContactsVtr .get(_grpDTO.get_contactIds() .elementAt(k)); CustomCheckBoxField _contactBtn = new CustomCheckBoxField( _contactDTO.get_fname() + " " + _contactDTO.get_lname(), (k % 2 == 0) ? false : true, false); // Logger.getInstance().logInformationEvent( // / "dsdddd hhh "); _contactBtn.set_obj(_contactDTO); // _contactBtn // .setFocusListener(ContactsScreen.this); _contactBtnList.addElement(_contactBtn); body.add(_contactBtn); } } // Logger.getInstance().logInformationEvent("dsdddd"); } catch (Exception e) { Dialog.alert("Network Error!"); Logger.getInstance().logInformationEvent( "eee" + e.toString() + e.getMessage()); }finally{ stop(); } return; } } public void stop() { super.stop(); } }
Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: OutOfMemoryError

wall of code hits you critically for over 9000 damage. you are unable to make sense and decide to retreat.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
madiha
Posts: 107
Registered: ‎05-26-2011
My Device: Torch

Re: OutOfMemoryError

public class CustomCheckBoxField extends CheckboxField {
	private ContactDTO _obj;

	String _text;
	Font _font = getFont().derive(Font.PLAIN, 7, Ui.UNITS_pt);
	Font _fontSmall = getFont().derive(Font.PLAIN, 6, Ui.UNITS_pt);
	boolean _paintBG = false;

	public Object get_obj() {
		return _obj;
	}

	public void set_obj(Object obj) {
		_obj = (ContactDTO) obj;
	}

	public CustomCheckBoxField(String label, boolean paintBG, boolean checked) {
		super(label, checked, Field.FOCUSABLE | Characters.BALLOT_X);

		_paintBG = paintBG;
	}

	public boolean isFocusable() {
		return true;
	}

	protected void onFocus(int direction) {
		super.onFocus(direction);
		invalidate();

	}

	protected void onUnfocus() {
		super.onUnfocus();
		invalidate();
	}

	protected void paint(Graphics graphics) {
		// super.paint(graphics);
		graphics.setFont(_font);
		if (getChecked()) {
			graphics.drawBitmap(5, getPreferredHeight()
					- Constants._check.getHeight() >> 1, Constants._check
					.getWidth(), Constants._check.getHeight(),
					Constants._check, 0, 0);
		} else {
			graphics.drawBitmap(5, getPreferredHeight()
					- Constants._uncheck.getHeight() >> 1, Constants._uncheck
					.getWidth(), Constants._uncheck.getHeight(),
					Constants._uncheck, 0, 0);

		}

		graphics.setColor(Color.BLACK);
		graphics
				.drawText(getLabel(), Constants._check.getWidth() + 15,
						getPreferredHeight()
								- (graphics.getFont().getHeight() * 2) >> 1);
		graphics.setFont(_fontSmall);
		graphics
				.drawText(_obj.get_title(), Constants._check.getWidth() + 15,
						(getPreferredHeight()
								- (graphics.getFont().getHeight()) >> 1) + 10);

		if (isFocus()) {
			graphics.setColor(0xFFFFFF);
		} else
			graphics.setColor(Color.GRAY);

	}

	protected void layout(int width, int height) {
		// TODO Auto-generated method stub
		super.layout(width, height);
		setExtent(getPreferredWidth(), getPreferredHeight());
	}

	public int getPreferredHeight() {
		// TODO Auto-generated method stub
		return Constants._bg.getHeight();
	}

	public int getPreferredWidth() {
		// TODO Auto-generated method stub
		return Constants._bg.getWidth();
	}

	protected void paintBackground(Graphics graphics) {
		super.paintBackground(graphics);
		if (_paintBG)
			graphics.drawBitmap(0, 0, Constants._bg.getWidth(), Constants._bg
					.getHeight(), Constants._bg, 0, 0);
		if (isFocus()) {
			graphics.drawBitmap(0, 0, Constants._hover.getWidth(),
					Constants._hover.getHeight(), Constants._hover, 0, 0);
		}
		graphics.setFont(_font);
		graphics.setColor(Color.BLACK);

	}

	protected void drawFocus(Graphics graphics, boolean on) {

	}

}




public class ContactsScreen extends MyMainScreen implements
		 OutboundMessageListener, FieldChangeListener,
		PhoneListener {
	TopPanel topPanel = new TopPanel(1,this);
	MasterManager master;
	com.frt.bcm.ui.custom.Header header = new com.frt.bcm.ui.custom.Header(
			Manager.FOCUSABLE | Manager.USE_ALL_WIDTH, "", Bitmap
					.getBitmapResource("hedaer-contacts.png"));
	private boolean _multiSelected = false;
	private boolean init = true;
	private LoaderThread _loader;
	private Vector _groups;
	private Vector _ungroupedContacs;
	VerticalFieldManager body;
	private Hashtable _allContactsVtr;
	private Vector _contactBtnList;
	private boolean CustomGroupExists = false;
	private SimpleSortingVector sortedGroups;
	private Hashtable phoneCallsHash = new Hashtable();
	private HistoryLog _phoneLog;
	private HistoryLog _smsLog;
	private HistoryLog _emailLog;
	private ContactDTO _currentContact;
	private Hashtable _emails;
	private Hashtable _smss;
	MessageConnection _mc;
	boolean _connected = false;

	public ContactsScreen() throws Exception {
		super(MainScreen.NO_SYSTEM_MENU_ITEMS);
		Phone.addPhoneListener(this);
		master = new MasterManager(Manager.NO_VERTICAL_SCROLL);
		master.add(header);
		master.add(topPanel);
		body = new VerticalFieldManager(Manager.VERTICAL_SCROLL
				| Manager.VERTICAL_SCROLL_MASK | Manager.VERTICAL_SCROLLBAR
				| Manager.VERTICAL_SCROLLBAR_MASK) {
			protected void sublayout(int maxWidth, int maxHeight) {
				super.sublayout(maxWidth, maxHeight);
				setExtent(Constants.width, Constants.height - topPanel._height
						- header._height);

			}
		};
		init();
		// / make a list of contact button fields iterate through them and get
		// selected fields objects and then extract value from their objects
		UiApplication.getUiApplication().invokeLater(new LoaderThread());
		body.setScrollListener(new ScrollChangeListener() {
			public void scrollChanged(Manager manager, int newHorizontalScroll,
					int newVerticalScroll) {
				//invalidate();
				master.invalidate();
			}
		});

		master.add(body);
		add(master);
		topPanel._contactsBtn.setFocus();

		// if (!checkReconnect())
		// UiApplication.getUiApplication().invokeLater(
		// new Thread(ContactsScreen.this));

	}

	private void init() throws Exception {

		_groups = (Vector) GroupsDatastore.retrieveData();
		_allContactsVtr = (Hashtable) ContactDataStore.retrieveData();
		// getUngroupedContacts();
		// Logger.getInstance().logInformationEvent(" groupd " + _groups);
		// Logger.getInstance().logInformationEvent(
		// "all contacts " + _allContactsVtr);
		boolean loadxml = false;
		if (_groups == null || _allContactsVtr == null)
			loadxml = true;
		else if (_groups.size() == 0)
			loadxml = true;

		if (_groups == null)
			throw new NetworkException("Network Exception");
		else {
			sortGroups();
			sortContacts();
		}
	}

	private void sortGroups() {
		try {
			if (_groups != null) {

				sortedGroups = new SimpleSortingVector();

				for (int i = 0; i < _groups.size(); i++) {
					GroupDTO grpDTO = (GroupDTO) _groups.elementAt(i);
					sortedGroups.addElement(grpDTO);

					Vector sortedIds;
					if (grpDTO.get_contactIds() != null) {
						sortedIds = getSortedContactEachGroup(grpDTO
								.get_contactIds(), true);
						grpDTO.set_contactIds(sortedIds);
					}
				}
				sortedGroups.setSortComparator(new Comparator() {
					public int compare(Object o1, Object o2) {
						String s1 = ((GroupDTO) o1).get_name();
						String s2 = ((GroupDTO) o2).get_name();
						
						return s1.toLowerCase().compareTo(s2.toLowerCase());
					}

					public boolean equals(Object obj) {
						return false;
					}
				});
				sortedGroups.setSort(true);
				
				_groups = sortedGroups;
				// _groups = sortedGroupsVector;
			}
		} catch (Exception e) {
			Logger.getInstance().logInformationEvent("das" + e.toString());
		}
	}
private class LoaderThread extends CustomThread {
		public void run() {

			synchronized (UiApplication.getUiApplication().getEventLock()) {

				// /
				try {
					body.deleteAll();
					if (_ungroupedContacs != null
							&& _ungroupedContacs.size() > 0) {
						body.add(new GroupBar("All Contacts"));
						_contactBtnList = new Vector();
					} else if (_groups != null && _groups.size() > 0) {
						_contactBtnList = new Vector();
					}
					int k = 0;
					if (_ungroupedContacs != null)
						for (int l = 0; l < _ungroupedContacs.size(); l++) {

							ContactDTO _contactDTO = (ContactDTO) _ungroupedContacs
									.elementAt(l);// _allContactsVtr
							// .get(_ungroupedContacs.elementAt(l));
							CustomCheckBoxField _contactBtn = new CustomCheckBoxField(
									_contactDTO.get_fname() + " "
											+ _contactDTO.get_lname(),
									(l % 2 == 0) ? false : true, false);
							_contactBtn.setChangeListener(ContactsScreen.this);
							_contactBtn.set_obj(_contactDTO);
						//	_contactBtn.setFocusListener(ContactsScreen.this);
							_contactBtnList.addElement(_contactBtn);
							body.add(_contactBtn);

						}
					// Logger.getInstance().logInformationEvent(
					// "eee 2ddd  " + _groups.size() + " "
					// + _allContactsVtr.size() + _contactBtnList);
					for (int i = 0; i < _groups.size(); i++) {
						GroupDTO _grpDTO = (GroupDTO) _groups.elementAt(i);
						GroupBar _grpHead = new GroupBar(_grpDTO.get_name());
						// Logger.getInstance().logInformationEvent(
						// "fff" + _grpDTO.is_isCustom());
						if (_grpDTO.is_isCustom())
							CustomGroupExists = true;
						// Logger.getInstance().logInformationEvent(
						// "dsdf " + _grpDTO.get_contactIds());
						body.add(_grpHead);
						if (_grpDTO.get_contactIds() != null)
							for (k = 0; k < _grpDTO.get_contactIds().size(); k++) {
								ContactDTO _contactDTO = (ContactDTO) _allContactsVtr
										.get(_grpDTO.get_contactIds()
												.elementAt(k));
								CustomCheckBoxField _contactBtn = new CustomCheckBoxField(
										_contactDTO.get_fname() + " "
												+ _contactDTO.get_lname(),
										(k % 2 == 0) ? false : true, false);
								// Logger.getInstance().logInformationEvent(
								// / "dsdddd hhh ");
								_contactBtn.set_obj(_contactDTO);
							//	_contactBtn
							//			.setFocusListener(ContactsScreen.this);
								_contactBtnList.addElement(_contactBtn);
								body.add(_contactBtn);
							}
					}
					// Logger.getInstance().logInformationEvent("dsdddd");

				} catch (Exception e) {
					Dialog.alert("Network Error!");
					Logger.getInstance().logInformationEvent(
							"eee" + e.toString() + e.getMessage());
				}finally{
					stop();
				}
				
				return;
			}
		}

		public void stop() {

			super.stop();
		}
	}

 above is the code of Contact screen which adds contacts in checkbox fields the checkboxfields are creetd from custom checkboxfield class i have pasted above .. Constant class has al static members  here i am using its bitmaps

public class CustomCheckBoxField extends CheckboxField {
	private ContactDTO _obj;

	String _text;
	Font _font = getFont().derive(Font.PLAIN, 7, Ui.UNITS_pt);
	Font _fontSmall = getFont().derive(Font.PLAIN, 6, Ui.UNITS_pt);
	boolean _paintBG = false;

	public Object get_obj() {
		return _obj;
	}

	public void set_obj(Object obj) {
		_obj = (ContactDTO) obj;
	}

	public CustomCheckBoxField(String label, boolean paintBG, boolean checked) {
		super(label, checked, Field.FOCUSABLE | Characters.BALLOT_X);

		_paintBG = paintBG;
	}

	public boolean isFocusable() {
		return true;
	}

	protected void onFocus(int direction) {
		super.onFocus(direction);
		invalidate();

	}

	protected void onUnfocus() {
		super.onUnfocus();
		invalidate();
	}

	protected void paint(Graphics graphics) {
		// super.paint(graphics);
		graphics.setFont(_font);
		if (getChecked()) {
			graphics.drawBitmap(5, getPreferredHeight()
					- Constants._check.getHeight() >> 1, Constants._check
					.getWidth(), Constants._check.getHeight(),
					Constants._check, 0, 0);
		} else {
			graphics.drawBitmap(5, getPreferredHeight()
					- Constants._uncheck.getHeight() >> 1, Constants._uncheck
					.getWidth(), Constants._uncheck.getHeight(),
					Constants._uncheck, 0, 0);

		}

		graphics.setColor(Color.BLACK);
		graphics
				.drawText(getLabel(), Constants._check.getWidth() + 15,
						getPreferredHeight()
								- (graphics.getFont().getHeight() * 2) >> 1);
		graphics.setFont(_fontSmall);
		graphics
				.drawText(_obj.get_title(), Constants._check.getWidth() + 15,
						(getPreferredHeight()
								- (graphics.getFont().getHeight()) >> 1) + 10);

		if (isFocus()) {
			graphics.setColor(0xFFFFFF);
		} else
			graphics.setColor(Color.GRAY);

	}

	protected void layout(int width, int height) {
		// TODO Auto-generated method stub
		super.layout(width, height);
		setExtent(getPreferredWidth(), getPreferredHeight());
	}

	public int getPreferredHeight() {
		// TODO Auto-generated method stub
		return Constants._bg.getHeight();
	}

	public int getPreferredWidth() {
		// TODO Auto-generated method stub
		return Constants._bg.getWidth();
	}

	protected void paintBackground(Graphics graphics) {
		super.paintBackground(graphics);
		if (_paintBG)
			graphics.drawBitmap(0, 0, Constants._bg.getWidth(), Constants._bg
					.getHeight(), Constants._bg, 0, 0);
		if (isFocus()) {
			graphics.drawBitmap(0, 0, Constants._hover.getWidth(),
					Constants._hover.getHeight(), Constants._hover, 0, 0);
		}
		graphics.setFont(_font);
		graphics.setColor(Color.BLACK);

	}

	protected void drawFocus(Graphics graphics, boolean on) {

	}

}




public class ContactsScreen extends MyMainScreen implements
		 OutboundMessageListener, FieldChangeListener,
		PhoneListener {
	TopPanel topPanel = new TopPanel(1,this);
	MasterManager master;
	com.frt.bcm.ui.custom.Header header = new com.frt.bcm.ui.custom.Header(
			Manager.FOCUSABLE | Manager.USE_ALL_WIDTH, "", Bitmap
					.getBitmapResource("hedaer-contacts.png"));
	private boolean _multiSelected = false;
	private boolean init = true;
	private LoaderThread _loader;
	private Vector _groups;
	private Vector _ungroupedContacs;
	VerticalFieldManager body;
	private Hashtable _allContactsVtr;
	private Vector _contactBtnList;
	private boolean CustomGroupExists = false;
	private SimpleSortingVector sortedGroups;
	private Hashtable phoneCallsHash = new Hashtable();
	private HistoryLog _phoneLog;
	private HistoryLog _smsLog;
	private HistoryLog _emailLog;
	private ContactDTO _currentContact;
	private Hashtable _emails;
	private Hashtable _smss;
	MessageConnection _mc;
	boolean _connected = false;

	public ContactsScreen() throws Exception {
		super(MainScreen.NO_SYSTEM_MENU_ITEMS);
		Phone.addPhoneListener(this);
		master = new MasterManager(Manager.NO_VERTICAL_SCROLL);
		master.add(header);
		master.add(topPanel);
		body = new VerticalFieldManager(Manager.VERTICAL_SCROLL
				| Manager.VERTICAL_SCROLL_MASK | Manager.VERTICAL_SCROLLBAR
				| Manager.VERTICAL_SCROLLBAR_MASK) {
			protected void sublayout(int maxWidth, int maxHeight) {
				super.sublayout(maxWidth, maxHeight);
				setExtent(Constants.width, Constants.height - topPanel._height
						- header._height);

			}
		};
		init();
		// / make a list of contact button fields iterate through them and get
		// selected fields objects and then extract value from their objects
		UiApplication.getUiApplication().invokeLater(new LoaderThread());
		body.setScrollListener(new ScrollChangeListener() {
			public void scrollChanged(Manager manager, int newHorizontalScroll,
					int newVerticalScroll) {
				//invalidate();
				master.invalidate();
			}
		});

		master.add(body);
		add(master);
		topPanel._contactsBtn.setFocus();

		// if (!checkReconnect())
		// UiApplication.getUiApplication().invokeLater(
		// new Thread(ContactsScreen.this));

	}

	private void init() throws Exception {

		_groups = (Vector) GroupsDatastore.retrieveData();
		_allContactsVtr = (Hashtable) ContactDataStore.retrieveData();
		// getUngroupedContacts();
		// Logger.getInstance().logInformationEvent(" groupd " + _groups);
		// Logger.getInstance().logInformationEvent(
		// "all contacts " + _allContactsVtr);
		boolean loadxml = false;
		if (_groups == null || _allContactsVtr == null)
			loadxml = true;
		else if (_groups.size() == 0)
			loadxml = true;

		if (_groups == null)
			throw new NetworkException("Network Exception");
		else {
			sortGroups();
			sortContacts();
		}
	}

	private void sortGroups() {
		try {
			if (_groups != null) {

				sortedGroups = new SimpleSortingVector();

				for (int i = 0; i < _groups.size(); i++) {
					GroupDTO grpDTO = (GroupDTO) _groups.elementAt(i);
					sortedGroups.addElement(grpDTO);

					Vector sortedIds;
					if (grpDTO.get_contactIds() != null) {
						sortedIds = getSortedContactEachGroup(grpDTO
								.get_contactIds(), true);
						grpDTO.set_contactIds(sortedIds);
					}
				}
				sortedGroups.setSortComparator(new Comparator() {
					public int compare(Object o1, Object o2) {
						String s1 = ((GroupDTO) o1).get_name();
						String s2 = ((GroupDTO) o2).get_name();
						
						return s1.toLowerCase().compareTo(s2.toLowerCase());
					}

					public boolean equals(Object obj) {
						return false;
					}
				});
				sortedGroups.setSort(true);
				
				_groups = sortedGroups;
				// _groups = sortedGroupsVector;
			}
		} catch (Exception e) {
			Logger.getInstance().logInformationEvent("das" + e.toString());
		}
	}
private class LoaderThread extends CustomThread {
		public void run() {

			synchronized (UiApplication.getUiApplication().getEventLock()) {

				// /
				try {
					body.deleteAll();
					if (_ungroupedContacs != null
							&& _ungroupedContacs.size() > 0) {
						body.add(new GroupBar("All Contacts"));
						_contactBtnList = new Vector();
					} else if (_groups != null && _groups.size() > 0) {
						_contactBtnList = new Vector();
					}
					int k = 0;
					if (_ungroupedContacs != null)
						for (int l = 0; l < _ungroupedContacs.size(); l++) {

							ContactDTO _contactDTO = (ContactDTO) _ungroupedContacs
									.elementAt(l);// _allContactsVtr
							// .get(_ungroupedContacs.elementAt(l));
							CustomCheckBoxField _contactBtn = new CustomCheckBoxField(
									_contactDTO.get_fname() + " "
											+ _contactDTO.get_lname(),
									(l % 2 == 0) ? false : true, false);
							_contactBtn.setChangeListener(ContactsScreen.this);
							_contactBtn.set_obj(_contactDTO);
						//	_contactBtn.setFocusListener(ContactsScreen.this);
							_contactBtnList.addElement(_contactBtn);
							body.add(_contactBtn);

						}
					// Logger.getInstance().logInformationEvent(
					// "eee 2ddd  " + _groups.size() + " "
					// + _allContactsVtr.size() + _contactBtnList);
					for (int i = 0; i < _groups.size(); i++) {
						GroupDTO _grpDTO = (GroupDTO) _groups.elementAt(i);
						GroupBar _grpHead = new GroupBar(_grpDTO.get_name());
						// Logger.getInstance().logInformationEvent(
						// "fff" + _grpDTO.is_isCustom());
						if (_grpDTO.is_isCustom())
							CustomGroupExists = true;
						// Logger.getInstance().logInformationEvent(
						// "dsdf " + _grpDTO.get_contactIds());
						body.add(_grpHead);
						if (_grpDTO.get_contactIds() != null)
							for (k = 0; k < _grpDTO.get_contactIds().size(); k++) {
								ContactDTO _contactDTO = (ContactDTO) _allContactsVtr
										.get(_grpDTO.get_contactIds()
												.elementAt(k));
								CustomCheckBoxField _contactBtn = new CustomCheckBoxField(
										_contactDTO.get_fname() + " "
												+ _contactDTO.get_lname(),
										(k % 2 == 0) ? false : true, false);
								// Logger.getInstance().logInformationEvent(
								// / "dsdddd hhh ");
								_contactBtn.set_obj(_contactDTO);
							//	_contactBtn
							//			.setFocusListener(ContactsScreen.this);
								_contactBtnList.addElement(_contactBtn);
								body.add(_contactBtn);
							}
					}
					// Logger.getInstance().logInformationEvent("dsdddd");

				} catch (Exception e) {
					Dialog.alert("Network Error!");
					Logger.getInstance().logInformationEvent(
							"eee" + e.toString() + e.getMessage());
				}finally{
					stop();
				}
				
				return;
			}
		}

		public void stop() {

			super.stop();
		}
	}

public class Constants {

	public static int width = 0;
	public static int height = 0;
	
	public static  Bitmap _check = Bitmap.getBitmapResource("check.png");
	public static Bitmap _uncheck = Bitmap.getBitmapResource("uncheck.png");

	public static Bitmap _bg = Bitmap.getBitmapResource("grey-bar-small.png");
	public static  Bitmap _hover = Bitmap.getBitmapResource("white-bar-smaller-hover.png");
}

yesterday i tried to post code but it didnot inserted the code on the code when i published the post... Here is the code of ContactsScreen which adds contacts in checkboxfields ...

Please use plain text.