07-15-2008 10:59 AM
I'm fairly new at this. Trying to obtain the amount of free memory with the following code, but the result is 0. Any ideas? JDE 4.5,8300 Simulator with 4.2
/*
* MemMark.java
*/
// imports
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.MemoryStats.*;
//extend the UiApplication
public class MemMark extends UiApplication
{
public static void main(String[] args)
{
//instance the app & start event thread
MemMark myApp = new MemMark();
myApp.enterEventDispatcher();
}
public MemMark()
{
//show the launch screen
pushScreen(new LaunchScreen());
}
}
//Create the launch screen, extend MainScreen
final class LaunchScreen extends MainScreen
{
public LaunchScreen()
{
//invoke the MainScreen constructor
super();
//get the current free memory
MemoryStats ms = new MemoryStats();
int m = ms.getFree();
//add the title
LabelField title = new LabelField("MemMark", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
//add text to the screen
add(new RichTextField("Available memory:"));
add(new RichTextField(String.valueOf(m)));
}
//override onClose() with exiting msg
public boolean onClose()
{
Dialog.alert("Exiting...");
System.exit(0);
return true;
}
}
Solved! Go to Solution.
07-15-2008 02:06 PM
JDE 4.5 and Sim 4.2?
Just a thought, but I think the Sim and JDE need to match (or Sim can be later), in the same way as for devices - see
What Is - Appropriate version of the BlackBerry JDE knowledge base article for assistance with choosing the correct version of the BlackBerry JDE for your environment:
07-15-2008 02:31 PM
07-15-2008 03:28 PM
The Memory class provides MemoryStats objects that contain the information you are looking for: http://www.blackberry.com/developers/docs/4.5.0api
Tim
07-15-2008 04:23 PM