简体   繁体   中英

unable to display sensor info on j2me

I've have written the following code to display the sensors available on the Nokia Asha phones.

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.List;
import javax.microedition.sensor.*;

public class Sensor extends Midlet {

    private Display display;
    private List sensorList;
    private SensorInfo[] sensorinfo;
    private Command exit, list;

    public void SensorBrowser(){

        display = Display.getDisplay(this);
        sensorList = new List("Available Sensors", List.EXCLUSIVE);

        sensorinfo = SensorManager.findSensors(null, null);

        for(int i = 0; i<sensorinfo.length; i++){
                 System.out.println("Sensor #" + (i+1) + ": Description: " +                       sensorinfo[i].getDescription());
        }
        exit = new Command("Exit", Command.EXIT, 1);
        list = new Command("Description", Command.ITEM, 1);
        sensorList.addCommand(list);
        sensorList.addCommand(exit);
        sensorList.setCommandListener((CommandListener) this); 
   }

}

When I try to run it on Asha Emulator, all I get is a blank screen.

This may seem like a basic question to many, but I'm new to j2me platform and I could not find any help in this matter.

Thank you.

Looks like you have done a refactoring and you have changed either the Midlet class name or the constructor function name, but forgot to change the other.

Another problem is your Midlet does not implement the CommandListener interface. And I can't see in your code where are you setting the list to the screen. You can do this in the startApp method, as in this example:

http://developer.nokia.com/Community/Wiki/Using_List_in_Java_ME

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM