我想在我的应用程序中有一个标签栏。我在黑莓中尝试了它的示例代码,但我希望它位于屏幕底部。我尝试了此代码,但它给了我未捕获的运行时异常。为什么会这样?这段代码有什么问题?
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.ui.image.*;
import net.rim.device.api.ui.toolbar.*;
import net.rim.device.api.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.command.*;
public class ToolbarDemo extends UiApplication
{
public static void main(String[] args)
{
ToolbarDemo theApp = new ToolbarDemo();
theApp.enterEventDispatcher();
}
public ToolbarDemo()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new ToolbarDemoScreen());
}
private final static class ToolbarDemoScreen extends MainScreen
{
public ToolbarDemoScreen()
{
if (ToolbarManager.isToolbarSupported())
{
setTitle("Toolbar Demo");
ToolbarManager manager = new ToolbarManager();
setToolbar(manager);
try
{
Bitmap myBitmap = Bitmap.getBitmapResource("myImg.jpg");
Image myImage = ImageFactory.createImage(myBitmap);
/*
* To create more buttons, Repeat the following lines
* up until manager.add()
*/
ToolbarButtonField button1 = new ToolbarButtonField(myImage, new StringProvider("butn1"));
button1.setCommandContext(new Object()
{
public String toString()
{
return "Button1";
}
});
button1.setCommand(new Command(new CommandHandler()
{
public void execute(ReadOnlyCommandMetadata metadata, Object context)
{
Dialog.alert("Executing command for " + context.toString());
}
}));
manager.add(new ToolbarSpacer(0));
manager.add(button1);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
else
{
Dialog.alert("The Toolbar is not supported on this device.");
}
}
}
}