Blackberry Browserfield example app not launching - blackberry

I'm attempting to run a very simple Blackberry/Java application which implements the BrowserField class. When I launch it in the simulator it just hangs. When I launch it on my device nothing happens.
JRE: 7.0
Simulator: 4.0.0.141
package mypackage;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public class BrowserJazz extends UiApplication
{
public static void main(String[] args)
{
BrowserJazz app = new BrowserJazz();
app.enterEventDispatcher();
}
public void BrowserJazz()
{
pushScreen(new BrowserFieldDemoScreen());
}
}
class BrowserFieldDemoScreen extends MainScreen
{
public BrowserFieldDemoScreen()
{
BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,
BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);
/*BrowserFieldListener listener = new BrowserFieldListener() {
public void documentLoaded(BrowserField browserField) throws Exception
{
// the document has loaded, do something ...
Dialog.inform("PAGE LOADED!");
}
};*/
add(browserField);
//browserField.addListener( listener );
browserField.requestContent("http://www.google.com");
//browserField.addListener( listener );
}
}
Any ideas?

You are using "NAVIGATION_MODE_POINTER" which only support OS 5 and above as you can read from browserfield doc http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/browser/field2/BrowserFieldConfig.html#NAVIGATION_MODE_POINTER
and as you said you using an old simulator "Simulator: 4.0.0.141"

Related

How to use Telugu font in blackberry application

As I'm novice in Blackberry/Java development, I don't know how to use "telugu" font in my Blackberry application. Please give an example.
see the difference between three simulators
9300-OS6 not displaying
9790-os7 displays only in this device .
9900-os7 even OS7 it is not displaying.
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import java.util.*;
public class FontLoadingDemo extends UiApplication
{
public static void main(String[] args)
{
FontLoadingDemo app = new FontLoadingDemo();
app.enterEventDispatcher();
}
public FontLoadingDemo()
{
pushScreen(new FontLoadingDemoScreen());
}
}
class FontLoadingDemoScreen extends MainScreen
{
public FontLoadingDemoScreen()
{
setTitle("Font Loading Demo");
LabelField helloWorld = new LabelField("Hello World");
if (FontManager.getInstance().load("Myfont.ttf", "MyFont", FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
{
try
{
FontFamily typeface = FontFamily.forName("MyFont");
Font myFont = typeface.getFont(Font.PLAIN, 50);
helloWorld.setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
add(helloWorld);
}
}
Source: http://docs.blackberry.com/en/developers/deliverables/11958/Load_and_use_a_custom_font_899948_11.jsp

Why button on screen not effect when I use postGlobalScreen to push this screen?

I edit Blackberry_App_Descriptor.xml to make my app is "Auto run on start up". My app have 3 classes, myApp, screen1 and screen2. MyApp with main method to push screen1. in screen1 have a button to push screen 2. It run OK when I launch appplication manualy. (click icon of App )
Problem is:
I use RealTimeListener to always check time each minutes, if it is 1h30 it will push screen1, ( I used method postGlobalScreen to push Screen1 ). And it pushed success. But i can use the button on this screen1, I clicked it and it not push to screen2.
I try to use Alternate Entry point to check time and push screen1 but it have the same result.
Can anybody help me solve and explain clearly about this problem ?
// MyApp.java
public class MyApp extends UiApplication implements RealtimeClockListener
{
/**
* Entry point for application
* #param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new Screen1());
addRealtimeClockListener(this);
}
public void clockUpdated() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
if(hour==1 && minute == 30){
UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);
}
}
}
//Screen1.java
public final class Screen1 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen1()
{
button = new ButtonField("Screen 1 ");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen2());
}
}
}
//Screen2.java
public final class Screen2 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen2()
{
button = new ButtonField("Screen2");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen1());
}
}
}
Please try following. here concentrate on two points
1)Application run in background background
2)send background application into foreground
package mypackage;
import java.util.Calendar;
import net.rim.device.api.system.RealtimeClockListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;
public class MyApp extends UiApplication implements RealtimeClockListener
{
/**
* Entry point for application
* #param args Command line arguments (not used)
*/
public static MyApp theApp=null;
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new Screen1());
addRealtimeClockListener(this);
}
public void clockUpdated() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
// if(hour==1 && minute == 30){
if(!theApp.isForeground())
{
UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);
}
}
}
screen1.java
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
public final class Screen1 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen1()
{
button = new ButtonField("Screen 1 ");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
close();
MyApp.theApp.requestForeground();
UiApplication.getUiApplication().pushScreen(new Screen2());
}
}
public boolean onClose() {
MyApp.theApp.requestBackground();
return true;
}
}
screen2.java
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
public final class Screen2 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen2()
{
button = new ButtonField("Screen2");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen1());
}
}
}

Blackberry: display Alert/Status/Dialog early and exit

Let's say I have a typical Blackberry app:
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
and already at the beginning I notice, that a mandatory condition is missing (wrong Display dimensions; missing SD card; some IT policy; etc.)
Is there a way to display a short and quick message to the user (in the form of Alert/Status/Dialog/whatever) and exit straight away - without/before instantiating a complex Screen/registering Acceleration listeners/installing complex CleanupRunnable?
I've tried Status.show(), Dialog.alert() - they do not work (RuntimeException "pushModalScreen called by a non-event thread"):
public class MyScreen extends MainScreen {
public MyScreen() {
if (Display.getWidth() < 400) {
Status.show("Goodbye");
return;
}
}
}
Instead of direct invocation use invokeLater. Sample is below:
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("Your message here...");
}
});
Instead of Dialog.inform you may use Status.show()
Actually the following is better, than what's suggested by Rafael - because it doesn't have the ugly white screen underneath. Here is my complete example MyApp.java:
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.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen implements DialogClosedListener {
Dialog myDialog = new Dialog(Dialog.OK, "Goodbye!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.GLOBAL_STATUS);
public MyScreen() {
// XXX just some condition, like wrong dimensions or IT policy
if (Display.getWidth() > 40) {
myDialog.setDialogClosedListener(this);
Application.getApplication().requestBackground();
Application.getApplication().invokeLater(new Runnable() {
public void run() {
myDialog.show();
}
});
return;
}
// XXX heavy stuff to be skipped
}
public void dialogClosed(Dialog dialog, int choice) {
if (dialog == myDialog) {
System.out.println("XXX exiting XXX");
System.exit(1);
}
}
}

JVM exception in simple program

I am writing a small demo program to display a message box in to run in blackberry. As soon as I click the OK button on the dialog, it throws me a JVM Error 104, uncaught:runtimeexception. Any help please? Here is the code :
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class My_First_App extends UiApplication
{
public static void main(String[] args)
{
My_First_App theApp = new My_First_App();
theApp.enterEventDispatcher();
}
public My_First_App()
{
pushScreen(new My_First_AppScreen());
}
}
final class My_First_AppScreen extends MainScreen
{
public My_First_AppScreen()
{
super();
HorizontalFieldManager _fieldmanager;
_fieldmanager = new HorizontalFieldManager();
/* declare one label to how the application title */
LabelField applicationtitle = new LabelField("Demo",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField _pairMe = new ButtonField("PairMe");
FieldChangeListener listenerPairMe = new FieldChangeListener() {
public void fieldChanged(Field field, int context){
Dialog.alert("You clicked the button!");
}
};
/*set the title*/
add(_fieldmanager);
setTitle(applicationtitle);
_fieldmanager.add(_pairMe);
_pairMe.setChangeListener(listenerPairMe);
}
public boolean onClose()
{
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
create a new workspace. It's related to Eclipse, not to your code

Blackberry how to display message in app if device got no internet connection?

I've just started with programming for the Blackberry device. I'm using version 5 of the API.
I'm building a very simple application which is just a browserfield. So far it's all working great. I can display my browserfield with the content I need.
The problem I'm having now is if the device doesn't have an active internet connection I get the ugly "Error requesting content for" message.
I would need to someone display my own message if the device doesn't have an active connection.
Something like "You need to have an active internet connection to use this application" with an Exit button which closes the app.
I've tried to find this for hours but no luck.
Hopefully it's something relatively easy so I can get help here.
Here's my code so far:
package com.mycompany.webview;
import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class webview extends UiApplication
{
public static void main(String[] args)
{
webview app = new webview();
app.enterEventDispatcher();
}
public webview()
{
pushScreen(new webviewScreen());
}
}
class webviewScreen extends MainScreen
{
public webviewScreen()
{
BrowserField myBrowserField = new BrowserField();
add(myBrowserField);
myBrowserField.requestContent("http://www.google.com");
}
}
Would really appreciate some help please.
Thanks
I got it working.
If anyone else is wondering how it's done, this is how I did it:
package com.mycompany.webview;
import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.CoverageInfo;
public class webview extends UiApplication
{
public static void main(String[] args)
{
webview app = new webview();
app.enterEventDispatcher();
}
public webview()
{
pushScreen(new webviewScreen());
}
}
class webviewScreen extends MainScreen
{
public webviewScreen()
{
if (CoverageInfo.isOutOfCoverage())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("You need an active internet connection to use this application");
System.exit(0);
}
});
}
else
{
BrowserField myBrowserField = new BrowserField();
add(myBrowserField);
myBrowserField.requestContent("http://www.google.com");
}
}
}

Resources