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: 2
Registered: ‎04-05-2009
My Device: Not Specified

Issues surrounding stackoverflow errors and threading

Hello everyone, I am new to BB development and am baffled by this issue. I'll post the code below, but to give a little background info first. I added the code from the HelloWorld app and modified it so that the icon is drawn in the screen. I wanted to go a little step further and animate the icon across the screen using a seperate thread. However I keep getting stackoverflow errors. Now the code follows ...

 

 

/** * HelloWorld.java * Copyright (C) 2001-2008 Research In Motion Limited. All rights reserved. */ package com.rim.samples.helloworld; // IMPORTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import net.rim.blackberry.api.homescreen.HomeScreen; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; /* * BlackBerry device applications that provide a UI * must extend the UiApplication class. */ public class Hello extends UiApplication { HelloWorldScreen hello = new HelloWorldScreen(); public static void main(String[] args) { //Create a new instance of the BlackBerry device pplication //and start the BlackBerry device application on the event thread. Hello theApp = new Hello(); theApp.enterEventDispatcher(); } public Hello() { //Display a new screen. pushScreen(hello); } } // Create a new screen that extends MainScreen and provides // Behavior similar to that of other BlackBerry device applications. final class HelloWorldScreen extends MainScreen { final Bitmap regIcon = Bitmap.getBitmapResource("helloworld_jde.png"); long prevTime = 0; int x=0; Updater updater; public HelloWorldScreen() { //Invoke the MainScreen constructor. super(); //Add a title to the screen. LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); //Add the text "Hello World!" to the screen. add(new RichTextField("Hello World!")); HomeScreen.updateIcon(regIcon); updater = new Updater(); updater.run(); } public void paint(Graphics g) { super.paint(g); g.drawBitmap(new XYRect(x,0,regIcon.getWidth(), regIcon.getHeight()), regIcon, 0, 0); } //To display a dialog box to a BlackBerry smartphone user with the text //"Goodbye!" when the BlackBerry smartphone user closes the BlackBerry device application, override the onClose() method. public boolean onClose() { Dialog.alert("Goodbye!"); updater.quit = true; System.exit(0); return true; } public void repaint() { this.repaint(); } class Updater implements Runnable { public boolean quit = false; public void run() { while (!quit) { x+=1; if(x>100) x = 0; repaint(); try { wait(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }

 

 

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

how in the #$@!%@#%  do I paste code, which is TEXT, without getting a bunch of garbage windows and scrolling etc????????  Which cave drawing suggests "get rid of formatting garbage????" 
 public void repaint() {
this.repaint(); }
Anyway, consider what the above does and step through it in debugger, after someone runs a script debugger to find out which stupid icon is supposed to let me paste code as if it were normal text. .... 
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

[ Edited ]

I think what marchywka is saying is that you have a recursive call to repaint(). Each call to paint makes another call to repaint(), which pushes the return address on the stack, eventually blowing the stack.

 

Maybe you meant to call super.repaint() ?? Not the same thing at all.

 

 

 

 

Message Edited by RexDoug on 04-05-2009 01:52 PM
New Developer
Posts: 2
Registered: ‎04-05-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

That was it. I completely overlooked it. Thx a bunch! :smileyhappy:
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

Yeah, usually when I get those things it is something I keep reading wrong...

 

Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Issues surrounding stackoverflow errors and threading

Hello, am facing the same problem but in a different context. how did you get out of that problem!!! it would be help ful for me and also the others.

 

 

 

Thanks and Regards,
PraveenGoparaju.