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
New Developer
Posts: 11
Registered: ‎03-25-2009
My Device: Not Specified
Accepted Solution

MainScreen IllegalArgumentException

[ Edited ]

IllegalArgumentException 

Exception detail is "Field is not a child of this manager."   

 

Scenario: I've subclassed MainScreen, and overridden sublayout().  Exception is thrown in my sublayout().  Relevant code ...

 

 



AppScreen()
{
super( NO_VERTICAL_SCROLL | DEFAULT_CLOSE );

_hdr = new MyHeader();
add( _hdr);
}

protected void sublayout(int mw, int mh)
{
super.sublayout( mw, mh);
layoutChild(_hdr, mw, 24);
setPositionChild(_hdr, 0, 0);
setExtent(mw, mh);
}

 

 The exception confuses me greatly.  I called add(_hdr) on my field up in this screen's constructor.  And yet it tells me it is not a child of the manager.  How can this be?

 

Thanks for any thoughts.

 

Platform: JDE 4.2.1

Simulator: 8800 

 

Message Edited by saggy on 03-27-2009 11:51 PM
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: MainScreen IllegalArgumentException

Can't really help you sorry, but I believe MainScreen actually has three Managers associated, one each for the title, body and status areas.  I'm not sure how it manages sublayout in this case.

 

Perhaps you could add _hdr to your own manager, which has sublayout overridden?

New Developer
Posts: 11
Registered: ‎03-25-2009
My Device: Not Specified

Re: MainScreen IllegalArgumentException

Yeah, I think you are right.

 

I tried MainScreen.getMainManager().add(), FullScreen.getManager().add(), etc.  All with no luck.  It seems that even those screen classes look and smell like Managers and Fields, they really aren't.  At least in the sense that you can't override sublayout.

 

Indeed, creating a manager, overriding its sublayout(), and adding the manager to the screen works fine.

 

Cheers. 

New Developer
Posts: 11
Registered: ‎12-06-2009
My Device: Not Specified

Re: MainScreen IllegalArgumentException

I had a similar problem.

I had to add another manager in the middle to control the layout. The screen has only one control - myManager which all oter control are being added to it.

MyManager is implementing sublayout

Highlighted
New Developer
Posts: 1
Registered: ‎12-13-2009
My Device: Curve 8520
My Carrier: Movilnet

Re: MainScreen IllegalArgumentException

Here is an example of this solution: http://www.thinkingblackberry.com/archives/188

 

The code of two (2) examples files, are pasted here:

 

FILE #1: ChatLayoutManager.java

 

  1. package com.thinkingblackberry;  
  2.   
  3. import net.rim.device.api.ui.Field;  
  4. import net.rim.device.api.ui.Manager;  
  5.   
  6. public class ChatLayoutManager extends Manager {  
  7.     private Field bottomField;  
  8.     private Field mainField;  
  9.     private Field titleField;  
  10.   
  11.     public ChatLayoutManager(long style) {  
  12.         super(style);  
  13.     }  
  14.   
  15.     protected void sublayout(int width, int height) {  
  16.         setExtent(width, height);  
  17.   
  18.         int y = 0;  
  19.         if (bottomField != null) {  
  20.             layoutChild(bottomField, width, height);  
  21.             // This goes at the bottom of the screen  
  22.             setPositionChild(bottomField, 0, height-bottomField.getHeight());  
  23.             height -= bottomField.getHeight();  
  24.         }  
  25.   
  26.         if (titleField != null) {  
  27.             layoutChild(titleField, width, height);  
  28.             // This goes at the top of the screen  
  29.             setPositionChild(titleField, 00);  
  30.             height -= titleField.getHeight();  
  31.             y += titleField.getHeight();  
  32.         }  
  33.   
  34.         if (mainField != null) {  
  35.             layoutChild(mainField, width, height);  
  36.             // This goes just below the title field (if any)  
  37.             setPositionChild(mainField, 0, y);  
  38.         }  
  39.   
  40.     }  
  41.   
  42.     public void setMainField(Field f) {  
  43.         mainField = f;  
  44.         add(f);  
  45.     }  
  46.   
  47.     public void setBottomField(Field f) {  
  48.         bottomField = f;  
  49.         add(f);  
  50.     }  
  51.   
  52.     public void setTitleField(Field f) {  
  53.         titleField = f;  
  54.         add(f);  
  55.     }  

 

FILE #2: ChatScreen.java


  1. package com.thinkingblackberry;  
  2.   
  3. import java.io.ByteArrayOutputStream;  
  4. import java.io.IOException;  
  5. import java.io.InputStream;  
  6.   
  7. import net.rim.device.api.ui.Field;  
  8. import net.rim.device.api.ui.FieldChangeListener;  
  9. import net.rim.device.api.ui.Manager;  
  10. import net.rim.device.api.ui.Screen;  
  11. import net.rim.device.api.ui.component.AutoTextEditField;  
  12. import net.rim.device.api.ui.component.EditField;  
  13. import net.rim.device.api.ui.component.RichTextField;  
  14. import net.rim.device.api.ui.container.VerticalFieldManager;  
  15.   
  16. public class ChatScreen extends Screen implements FieldChangeListener {  
  17.     private ChatLayoutManager chatManager;  
  18.     private RichTextField richTextField;  
  19.     private EditField editField;  
  20.   
  21.     public ChatScreen() {  
  22.         super(new ChatLayoutManager(0), Screen.DEFAULT_CLOSE | Screen.DEFAULT_MENU);  
  23.   
  24.         chatManager = (ChatLayoutManager)getDelegate();  
  25.   
  26.         VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);  
  27.         String str = getSampleText();  
  28.   
  29.         richTextField = new RichTextField(str);  
  30.         vfm.add(richTextField);  
  31.         editField = new AutoTextEditField("Chat:""");  
  32.         editField.setChangeListener(this);  
  33.         chatManager.setBottomField(editField);  
  34.         chatManager.setMainField(vfm);  
  35.     }  
  36.   
  37.     protected void sublayout(int width, int height) {  
  38.         setPositionDelegate(00);  
  39.         layoutDelegate(width, height);  
  40.         setPosition(00);  
  41.         setExtent(width, height);  
  42.     }  
  43.   
  44.     public void fieldChanged(Field field, int context) {  
  45.         if (field == editField) {  
  46.             String text = editField.getText();  
  47.             if (text.length() > 0 && text.charAt(text.length()-1) == '\n') {  
  48.                 editField.setText(text.substring(0, text.length() - 1));  
  49.                 richTextField.setCursorPosition(richTextField.getTextLength()-1);  
  50.                 richTextField.setFocus();  
  51.             }  
  52.         }  
  53.     }  
  54.   
  55.     private String getSampleText() {  
  56.         String str = "";  
  57.         try {  
  58.             InputStream is = getClass().getResourceAsStream("/res/lipsum.txt");  
  59.             ByteArrayOutputStream baos = new ByteArrayOutputStream();  
  60.             byte[] buffer = new byte[4096];  
  61.             int read = is.read(buffer);  
  62.             while(read > 0) {  
  63.                 baos.write(buffer, 0, read);  
  64.                 read = is.read(buffer);  
  65.             }  
  66.             is.close();  
  67.             baos.close();  
  68.             str = new String(baos.toByteArray());  
  69.         } catch (IOException ex) {  
  70.   
  71.         }  
  72.         return str;  
  73.     }  
  74.   
  75. }