MIDlet navigation

Hi all

Forgive me if this has been asked before.

It is a basic question about MIDlet navigation.

Supossing I have a MIDlet that displays a form which is basically a menu.

Then each menu option the user selects is another displayable object. EG. Form or Canvas etc.

The current way I have coded it is within my commandAction or itemAction I do

Code:

if ( action == someAction )

{

instance.display.setCurrent(new MyForm() );

}

elseif ( action == someAction )

{

instance.display.setCurrent(new MyOtherForm() );

}

is this the right way to perform MIDlet navigation? Or should it be a a suite of MIDlets?

Basically it seems as if the above is wrong? because when I run this on the emulator Nokia or WTK it works fine but running on a target device (In this case Nokia 6600 ) it errors? which seems to be a memory error?

I can post the Page it is supposed to be display if anyone wants to see that?

Any ideas?

Regards

eggsy

[1316 byte] By [jimbobegga] at [2007-11-26 21:57:29]
# 1

it may not cause errors but mobile devices are weird!!

so, what is instance?

and the thing that you can do is...

you have a root MIDlet with few methods to display differents Dsiplayable objects...

each Displayable object has a reference to the root MIDlet...

when you want to change screen, call the method from the root MIDlet

// in the event listener method

rootMidlet.displayNow("menu"); // or whatever

...

and in the root MIDlet

Display display=Display.getDisplay(this);

...

public void displayNow(String str){

if(str.equals("menu"){

display.setCurrent(myMenu);

}

// etc...

}

or use diffetrents MIDlet. for this, you can check the apps in the WTK (use ktoolbar bin to

play them)

hope this help

~sup@reno

suparenoa at 2007-7-10 3:54:39 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Ok thank youWill try the navigation you said first then if no luck will try the suite of MIDletsthanks for the reply
jimbobegga at 2007-7-10 3:54:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Have tried the above change but to no luck!?

I'm testing on a Nokia 6600 and get the following error:

App. closed jes-97-javax.microeditionlcdui@....

Anyone seen this? before? Sorry I can't be more descriptive but thats all you can see of the error on the devices display.

PS. I have ran the application on the series 60 Nokia emulator successfully?!?!

jimbobegga at 2007-7-10 3:54:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

This is a sample page that wont display:

package com.paje.app.menu;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import javax.microedition.lcdui.ChoiceGroup;

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener;

import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Form;

import javax.microedition.lcdui.Item;

import javax.microedition.lcdui.ItemCommandListener;

import javax.microedition.lcdui.StringItem;

import javax.microedition.rms.RecordStore;

import javax.microedition.rms.RecordStoreException;

import com.paje.app.Pajelet;

import com.paje.app.bluetooth.BluetoothServer;

import com.paje.app.persistent.UserStatus;

public class ActivatePage extends Form implements CommandListener, ItemCommandListener

{

//Status statics

private static final int INVISIBLE = 0;

private static final int VISIBLE = 1;

private ChoiceGroup statusField;

private Item saveButton;

private RecordStore statusData;

private boolean openedRecordStore = false;

private static final Command SAVE_CMD = new Command("Save", Command.ITEM, 2);

private static final Command MENU_BACK_CMD = new Command("Back", Command.BACK, 0);

private static final String RECORD_STORE = "Visibility";

//Make us a Bluetooth Server?!

private BluetoothServer btServer;

public ActivatePage()

{

super( "Activate Matching");

addCommand(MENU_BACK_CMD);

setCommandListener(this);

openRecordStore();

UserStatus userStatus = loadStatus();

statusField = new ChoiceGroup("Status:", ChoiceGroup.EXCLUSIVE );

statusField.insert(INVISIBLE, "Invisible", null);

statusField.insert(VISIBLE, "Visible", null);

//Get the users stored status

//0 for not active 1 for active

int status = userStatus.getActive();

if ( status == 0 )

{

statusField.setSelectedIndex(0, true);

}

else

{

statusField.setSelectedIndex(1, true);

}

append( statusField );

saveButton = new StringItem("", "Save Changes", Item.BUTTON );

saveButton.setDefaultCommand(SAVE_CMD);

saveButton.setItemCommandListener(this);

append( saveButton );

btServer = new BluetoothServer();

}

public void openRecordStore()

{

try

{

statusData = RecordStore.openRecordStore(RECORD_STORE, true);

openedRecordStore = true;

}

catch(RecordStoreException e )

{

System.err.println( "Error opening record store" );

return;

}

}

public void closeRecordStore()

{

if ( openedRecordStore )

{

try

{

statusData.closeRecordStore();

openedRecordStore = false;

}

catch (RecordStoreException e)

{

}

}

}

public void deleteRecordStore()

{

closeRecordStore();

if (RecordStore.listRecordStores() != null)

{

try

{

RecordStore.deleteRecordStore(RECORD_STORE);

}

catch (RecordStoreException e)

{

System.err.println( "Could not delete the record store");

e.printStackTrace();

}

}

}

public void commandAction(Command c, Displayable d)

{

if ( c == MENU_BACK_CMD )

{

closeRecordStore();

Pajelet.display.setCurrent( new MainMenu());

}

}

public void commandAction(Command c, Item i)

{

if ( c == SAVE_CMD )

{

try

{

saveChanges();

if ( statusField.getSelectedIndex() == VISIBLE )

{

System.out.println( "Bluetooth Activation going online...");

btServer.startServer();

}

else

{

System.out.println( "Bluetooth Activation going offline....");

btServer.stopServer();

}

}

catch( Exception err )

{

System.err.println( "Exception thrown during Saving activation: \n" + err );

}

closeRecordStore();

String message = " Your activity has now been changed";

SavedChanges.showSavedConfirmation( message, Pajelet.display );

}

}

public UserStatus loadStatus()

{

UserStatus user = null;

try

{

byte [] data = statusData.getRecord(1);

DataInputStream is = new DataInputStream( new ByteArrayInputStream(data));

user = new UserStatus();

user.setActive(is.readInt());

is.close();

}

catch (Exception e )

{

//User has not saved changes and thus we just need to create one

user = new UserStatus();

}

return user;

}

public void saveChanges() throws Exception

{

deleteRecordStore();

if ( !openedRecordStore )

{

openRecordStore();

}

UserStatus userStatus = new UserStatus();

if ( statusField.getSelectedIndex() == 0 )

{

userStatus.setActive( 0 );

}

else

{

userStatus.setActive( 1 );

}

ByteArrayOutputStream baos = new ByteArrayOutputStream();

DataOutputStream os = new DataOutputStream(baos);

os.writeInt(userStatus.getActive() );

os.close();

byte[] data = baos.toByteArray();

statusData.addRecord(data, 0, data.length);

}

Does there seem to be anything that the 6600 wouldnt support?

jimbobegga at 2007-7-10 3:54:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

Hey

Are you creating seperate Midlet extended class?

If yes then plz show that code so that we can make sure that u are following proper Midlet life cycle and importing all important packages.

For your convenience I can give you an example how we do navigation in btw high level components on midlet:::

--

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

public class ABC extends MIDlet implements CommandListener, ItemStateListener {

public Display display;

protected Form form1, form2;

private Command commandForm2 = new Command("Next", Command.SELECT, 5);

public ABC(){

display = Display.getDisplay(this);

form1 = new Form("Form 1");

form2 = new Form("Form 2");

form1.addCommand(commandForm2);

form1.setCommandListener(this);

form1.setItemStateListener(this);

}

public void startApp() {

display.setCurrent(form1);

}

protected void pauseApp() {

}

protected void destroyApp(boolean unconditional) {

}

public void commandAction(Command command, Displayable displayable) {

if (command == commandForm2{

display.setCurrent(form2);

}

It is just a rough idea I hope it will help you.

If any more query then clear in next post with proper errors which it is showing when u run on different different phones.

Regards!

J2meFighter

J2meFightera at 2007-7-10 3:54:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Hi sorry for being slightly unclear on this.

I only have one MIDlet extended class, and do perform the navigation as you highlighted before.

I have narrowed it down to that specific class I have included below.

Form example if I new up that class in my MIDlet constructor like you have shown here:

form1 = new Form("Form 1");

My MIDlet does not start at all proving that it is the newing up of my problem class that is the problem rather than my navigation methods.

The actual error I get on my Nokia 6600 is this:

App. closed jes-97-javax.microeditionlcdui@....

Sorry I cant provide any more of the error as the devices display does not allow it?

jimbobegga at 2007-7-10 3:54:40 > top of Java-index,Java Mobility Forums,Java ME Technologies...