Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:19:11+00:00 2026-06-07T04:19:11+00:00

I am trying to type in characters to fill an editfield, if the text

  • 0

I am trying to type in characters to fill an editfield, if the text is still on the first line I have got no problem but when the first line is full then it goes to the next line and I get the following error:

0:01:56.609: Uncaught: StackOverflowError

Here is my custom_editfield:

public class Custom_EditField extends EditField {

int width, row;

Custom_EditField(long style, int width, int row) {
    super(style);
    this.width = width;
    this.row = row;
}

public int getPreferredHeight() {
    return Font.getDefault().getHeight() * row;
}

public int getPreferredWidth() {
    return width;
}

protected void layout(int maxWidth, int maxHeight) {
    super.layout(maxWidth,
            Math.min(maxHeight, Font.getDefault().getHeight() * row));
    super.setExtent(maxWidth,
            Math.min(maxHeight, Font.getDefault().getHeight() * row));
}

/*public int drawText(Graphics graphics, int offset, int length, int x,
        int y, DrawTextParam drawTextParam) {
    graphics.setBackgroundColor(Color.GRAY);
    graphics.clear();
    graphics.setColor(Color.BLACK);
    int labelWidth = getFont().getAdvance(getLabel());
    graphics.drawRect(labelWidth, 0, getWidth() - labelWidth, getHeight());
    return graphics.drawText(
            this.getText().substring(offset, offset + length), x, y);
}*/

protected void paint(Graphics graphics) {
    int rectHeight = getPreferredHeight();
    int rectWidth = getPreferredWidth();
    graphics.setBackgroundColor(Color.GRAY);
    graphics.clear();
    graphics.setColor(Color.BLACK);
    graphics.drawRect(0, 0, rectWidth, rectHeight);
    super.paint(graphics);
}
}

I also noticed that the cursor is transparent. Do you think that the cursor could cause this problem?

Here is I call the editfield

extends VerticalFIeldManager

protected void sublayout(int width, int height) {

    comments = new Custom_EditField(Field.FIELD_HCENTER
            | Field.FIELD_VCENTER | Field.FOCUSABLE,
            getPreferredWidth() - 10, 3);
    add(comments);

    namelabel = new Custom_LabelField("姓名:", DrawStyle.ELLIPSIS
            | LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | Field.FIELD_LEFT);
    namelabel.setFont(Font.getDefault().derive(Font.BOLD, 20));
    namelabel.setFontColor(Color.BLACK);
    add(namelabel);

    postbtn = new ButtonField("留言", DrawStyle.HCENTER | Field.FIELD_RIGHT);
    postbtn.setPadding(0, 20, 0, 20);
    postbtn.setChangeListener(this);
    add(postbtn);

    name = new Custom_EditField(Field.FIELD_HCENTER | Field.FIELD_VCENTER
            | Field.FOCUSABLE, getPreferredWidth()
            - namelabel.getPreferredWidth() - postbtn.getContentWidth() - 5
            * 4, 1);
    add(name);

    Field field = getField(0);
    layoutChild(field, getPreferredWidth() - 10,
            comments.getPreferredHeight());
    setPositionChild(field, 5, 5);

    field = getField(1);
    layoutChild(field, Font.getDefault().getAdvance(namelabel.getText()),
            namelabel.getContentHeight());
    setPositionChild(field, 5, comments.getPreferredHeight() + 5 * 2);

    field = getField(2);
    layoutChild(field, postbtn.getPreferredWidth() + postbtn.getWidth(),
            name.getPreferredHeight());
    setPositionChild(field, getPreferredWidth() - (postbtn.getWidth() + 5),
            comments.getPreferredHeight() + 5 * 2);

    field = getField(3);
    layoutChild(field, getPreferredWidth() * 2 / 3,
            name.getPreferredHeight());
    setPositionChild(field, namelabel.getWidth(),
            comments.getPreferredHeight() + 5 * 2);

    width = Math.min(width, getPreferredWidth());
    height = Math.min(height, getPreferredHeight());
    setExtent(width, height);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:19:12+00:00Added an answer on June 7, 2026 at 4:19 am

    The Solution

    I still can’t build your code, because the Manager code posted uses the class Custom_LabelField, which you haven’t shown. However, I would assume that Custom_LabelField is somewhat like a LabelField. If I assign name to be a LabelField, then I see your StackOverflowError.

    Just as @EugenMartynov said, you are setting the text of a label field inside your implementation of sublayout(). This actually causes sublayout() to be called again, from within itself. This causes namelabel to be created again, and the process repeats infinitely until the stack is exhausted.

    Really, the sublayout() method should only be used for layout operations: positioning and sizing. You should normally create your Field objects before that. Normally, that happens in the constructor. If you move the first half of your sublayout method to the constructor, you’ll fix this problem:

    public class MyManager extends VerticalFieldManager {
       public MyManager() {
          super(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    
          comments = new Custom_EditField(Field.FIELD_HCENTER 
            | Field.FIELD_VCENTER | Field.FOCUSABLE, 
            getPreferredWidth() - 10, 3); 
          add(comments); 
    
          namelabel = new Custom_LabelField("姓名:", DrawStyle.ELLIPSIS 
            | LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | Field.FIELD_LEFT); 
          namelabel.setFont(Font.getDefault().derive(Font.BOLD, 20)); 
          namelabel.setFontColor(Color.BLACK); 
          add(namelabel); 
    
          postbtn = new ButtonField("留言", DrawStyle.HCENTER | Field.FIELD_RIGHT); 
          postbtn.setPadding(0, 20, 0, 20); 
          postbtn.setChangeListener(this); 
          add(postbtn); 
    
          name = new Custom_EditField(Field.FIELD_HCENTER | Field.FIELD_VCENTER 
            | Field.FOCUSABLE, getPreferredWidth() 
            - namelabel.getPreferredWidth() - postbtn.getContentWidth() - 5 
            * 4, 1); 
          add(name); 
       }
    }
    

    Then sublayout() becomes simpler:

    protected void sublayout(int height, int width) {
       Field field = getField(0);    
       layoutChild(field, getPreferredWidth() - 10,    
            comments.getPreferredHeight());    
       setPositionChild(field, 5, 5);    
    
       field = getField(1);    
       layoutChild(field, Font.getDefault().getAdvance(namelabel.getText()),    
            namelabel.getContentHeight());    
       setPositionChild(field, 5, comments.getPreferredHeight() + 5 * 2);    
    
       field = getField(2);    
       layoutChild(field, postbtn.getPreferredWidth() + postbtn.getWidth(),    
            name.getPreferredHeight());    
       setPositionChild(field, getPreferredWidth() - (postbtn.getWidth() + 5),    
            comments.getPreferredHeight() + 5 * 2);    
    
       field = getField(3);    
       layoutChild(field, getPreferredWidth() * 2 / 3,    
            name.getPreferredHeight());    
       setPositionChild(field, namelabel.getWidth(),    
            comments.getPreferredHeight() + 5 * 2);    
    
       width = Math.min(width, getPreferredWidth());    
       height = Math.min(height, getPreferredHeight());    
       setExtent(width, height);    
    }
    

    General Information

    If you want to know how to catch a StackOverflowError, put this code in your top level UiApplication subclass (just for debugging … remove it before releasing your app):

      try {
         MyApp theApp = new MyApp();       
         theApp.enterEventDispatcher();
      } catch (Throwable e) {
         e.printStackTrace();
      }
    

    After it hits the line e.printStackTrace(), your Eclipse Console window will show something like this:

    [375.664]  0x16 
    [375.664] HelloBlackBerry(4FF4123E) 
    [375.664]  MyManager 
    [375.664]  sublayout 
    [375.664]  0x16 
    [375.664] HelloBlackBerry(4FF4123E) 
    [375.664]  MyManager 
    [375.664]  sublayout 
    [375.664]  0x16 
    [375.664] HelloBlackBerry(4FF4123E) 
    [375.664]  MyManager 
    [375.664]  sublayout 
    [375.664]  0x16 
    [375.664] HelloBlackBerry(4FF4123E) 
    [375.664]  MyManager 
    [375.664]  sublayout 
    [375.664]  0x16 
    [375.664] HelloBlackBerry(4FF4123E)
    

    You can see, over and over, with almost the exact same timestamp (375.664), the sublayout method in the MyManager class is being called. When you see that, you know you need to look at that method, because it’s calling itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a browser text box that my users type into. I am trying
I am trying to have a multi line textbox that when you type in
I'm trying to understand type patterns and generic classes in Haskell but can't seem
Trying to send a complex type between two systems that have the same code
I'm trying to implement a custom field type for my Symfony2 forms but for
I have a textbox for proving username. But I want to restrict special characters
im trying to use this method to make my characters but i get the
im trying to use this method to make my characters but i get the
I am trying to convert the characters in the textbox to upper case. But
I am trying to display non-printable characters (space, line break) in a winforms multiline

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.