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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Append String in StringBuffer

I have found this code which allows me to display my String on the screen. The current code is after a String is display, it will be clear to display the next one. I don't want it to be cleared but be able to see even when the next String is being display.

 

How do I change my code in order to do this?

 

 

    private void updateContent( final String text)
    {
        // This will create significant garbage, but avoids threading issues
        // (compared with creating a static Runnable and setting the text).
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                _content.setText(text);
            }
        });
    }

Contributor
Posts: 13
Registered: ‎07-20-2010
My Device: 9550

Re: Append String in StringBuffer

You can append to stringbuffer as:

 

StringBuffer buffer = new StringBuffer();

 

then u can append to that "buffer" as:

 

String text = "test";

buffer.append(text);

 

u check append method for more details.

 

 

Contributor
Posts: 16
Registered: ‎03-01-2011
My Device: 9700
My Carrier: Airtel

Re: Append String in StringBuffer

In case if you wanna see the old String with the new String try appending the old string to the new one.

 

  private void updateContent( final String text)
    {
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {

                 String oldtext = _content.getText().toString()+" "+text;


                _content.setText(oldtext);
            }
        });
    }

 

Hope this will solve your problem.

Regards,
KatharNavaS.
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: Append String in StringBuffer

I have tried your code but it has uncaught exception:Application is not responding; process terminated.

 

Why is this happening?

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Append String in StringBuffer

 


rosemary123 wrote:

I have tried your code but it has uncaught exception:Application is not responding; process terminated.

 

Why is this happening?


most likely you block the event thread, for example by executing networking without a separate thread.

 

----------------------------------------------------------
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
Contributor
Posts: 16
Registered: ‎03-01-2011
My Device: 9700
My Carrier: Airtel

Re: Append String in StringBuffer

You should better provide us the code to see how you make that call.

 

I too hope as simon suggested you will be trying to do the networking in the same thread and trying to update the UI which may result in your problem.

 

 

Regards,
KatharNavaS.
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: Append String in StringBuffer

[ Edited ]

I believe this is the code which is stopping app.

 

public String download()
        {         s = (StreamConnection)Connector.open(DOWNLOAD_PAGE);
                httpConn = (HttpConnection)s;  
               
                httpConn.setRequestMethod( HttpConnection.POST );
                httpConn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
                httpConn.setRequestProperty("Accept", "text/plain");
                dos = httpConn.openDataOutputStream();          
                status = httpConn.getResponseCode();
                contentLength = httpConn.getHeaderField("Content-Length");            
                if (status == HttpConnection.HTTP_OK)
                { 
                    while ( -1 != (length = input.read(data)) )
                    {
                         updateContent("DOWNLOADING: " + a + " KB" + "/" + d + " KB");    
                        onScreen.append( new String(data, 0, length));                
                        size += length;     
                    }
                    content = onScreen.toString();                  
                }                            
                else
                {                            
                    content = "response code " + status;
                }  
                s.close();                    
            }
            catch (Exception e)
            {       
                errorDialog(e.toString());                        
                return e.toString();
            }
            return content;
            
            
        }

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Append String in StringBuffer

This is obviously a blocking code. How do you invoke this download() method?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: Append String in StringBuffer

[ Edited ]

What do u mean by blocking code?

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Append String in StringBuffer

The code which waits for some events in order to continue execution. This is normal for multi-threaded environment (when a Thread blocks, another has a chance to work), but there are Threads which cannot have such blocking calls.  The most obvious one is the Event Thread:

What is the Event Thread?

Watch the above video very closely - it will shed a light on what you are doing wrong. Once you are done, think how you invoke that download() method.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!