×

Discussion Board

Results 1 to 12 of 12

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    32

    Problem in integrating zxing to j2me for nokia mobile paltform

    I am developing a 2d barcode scanner using zxing library on j2me for nokia mobile paltform using Nokia SDK 1.1 for java.

    When I run the ZXing MIDlet in the emulator I am getting this message:ZXing MIDlet running.nothing to display.

    But it is not displaying the menu that it supposed to display.

    I am new to J2ME,so please help me out.

    Menu.java


    final class Menu extends List implements CommandListener {

    private final ZXingMIDlet zXingMIDlet;
    private final Command cancelCommand;
    private final Command barcodeCommand;


    Menu(ZXingMIDlet parent, String title, String item) {
    super(title, IMPLICIT); // Set the title of the form
    zXingMIDlet = parent;
    // Build the UI components
    cancelCommand = new Command("Cancel", Command.CANCEL, 0);
    barcodeCommand = new Command(item, Command.ITEM, 0);
    addCommand(cancelCommand);
    addCommand(barcodeCommand);
    setCommandListener(this);
    }


    public String getSelectedString() {
    String result = "";
    if (getSelectedIndex() != -1) {
    result = getString(getSelectedIndex());
    }
    return result;
    }

    public void clear() {
    while (size() != 0) {
    delete(0);
    }
    }


    public void commandAction(Command command, Displayable displayable) {
    if (command == cancelCommand) {
    Display.getDisplay(zXingMIDlet).setCurrent(zXingMIDlet.getCanvas());
    } else if (command == barcodeCommand || command == SELECT_COMMAND) {
    if (getSelectedIndex() != -1) {
    zXingMIDlet.itemRequest();
    }
    }
    }

    }


    ZXingMIDlet.java

    public final class ZXingMIDlet extends MIDlet {

    private static final int ALERT_TIMEOUT_MS = 5 * 1000;

    private Canvas canvas;
    private Player player;
    private VideoControl videoControl;
    private Alert confirmation;
    private Alert alert;
    private Menu history;
    private Vector resultHistory;

    Displayable getCanvas() {
    return canvas;
    }

    Player getPlayer() {
    return player;
    }

    VideoControl getVideoControl() {
    return videoControl;
    }

    static MultimediaManager buildMultimediaManager() {
    return new AdvancedMultimediaManager();
    // Comment line above / uncomment below to make the basic version
    // return new DefaultMultimediaManager();
    }

    protected void startApp() throws MIDletStateChangeException {

    try {

    Image image = Image.createImage("/res/zxing-icon.png");
    Displayable splash = new SplashThread(this, 2000, image);
    Display.getDisplay(this).setCurrent(splash);

    resultHistory = new Vector(5);
    System.out.println("hello--------------");
    history = new Menu(this, "Scan History", "Use");
    System.out.println("hi--------------");
    player = createPlayer();
    player.realize();
    MultimediaManager multimediaManager = buildMultimediaManager();
    multimediaManager.setZoom(player);
    multimediaManager.setExposure(player);
    multimediaManager.setFlash(player);
    videoControl = (VideoControl) player.getControl("VideoControl");
    canvas = new VideoCanvas(this);
    canvas.setFullScreenMode(true);
    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas);
    videoControl.setDisplayLocation(0, 0);
    videoControl.setDisplaySize(canvas.getWidth(), canvas.getHeight());
    System.out.println("bye--------------");
    } catch (IOException ioe) {
    throw new MIDletStateChangeException(ioe.toString());
    } catch (MediaException me) {
    throw new MIDletStateChangeException(me.toString());
    }

    // Set up one confirmation and alert object to re-use
    confirmation = new Alert(null);
    confirmation.setType(AlertType.CONFIRMATION);
    confirmation.setTimeout(ALERT_TIMEOUT_MS);
    Command yes = new Command("Yes", Command.OK, 1);
    confirmation.addCommand(yes);
    Command no = new Command("No", Command.CANCEL, 1);
    confirmation.addCommand(no);
    alert = new Alert(null);
    alert.setTimeout(ALERT_TIMEOUT_MS);
    }

    void splashDone() {
    try {
    videoControl.setVisible(true);
    player.start();
    } catch (MediaException me) {
    showError(me);
    }
    Display.getDisplay(this).setCurrent(canvas);
    }

    private static Player createPlayer() throws IOException, MediaException {

    Player player = null;
    String platform = System.getProperty("microedition.platform");
    if (platform != null && platform.indexOf("Nokia") >= 0) {
    try {
    player = Manager.createPlayer("capture://image");
    } catch (MediaException me) {
    // if this fails, just continue with capture://video
    } catch (NullPointerException npe) {
    } catch (Error e) {

    }
    }
    if (player == null) {
    try {
    player = Manager.createPlayer("capture://video");
    } catch (NullPointerException npe) {

    throw new MediaException("Image/video capture not supported on this phone");
    }
    }
    return player;
    }

    protected void pauseApp() {
    if (player != null) {
    try {
    player.stop();
    } catch (MediaException me) {
    // continue?
    showError(me);
    }
    }
    }

    protected void destroyApp(boolean unconditional) {
    if (player != null) {
    videoControl = null;
    try {
    player.stop();
    } catch (MediaException me) {
    // continue
    }
    player.deallocate();
    player.close();
    player = null;
    }
    }

    void stop() {
    destroyApp(false);
    notifyDestroyed();
    }

    void historyRequest() {
    Display.getDisplay(this).setCurrent(history);
    }


    private void showOpenURL(String title, String display, final String uri) {
    confirmation.setTitle(title);
    confirmation.setString(display);
    CommandListener listener = new CommandListener() {
    public void commandAction(Command command, Displayable displayable) {
    if (command.getCommandType() == Command.OK) {
    try {
    platformRequest(uri);
    } catch (ConnectionNotFoundException cnfe) {
    showError(cnfe);
    } finally {
    stop();
    }
    } else {
    // cancel
    Display.getDisplay(ZXingMIDlet.this).setCurrent(getCanvas());
    }
    }
    };
    confirmation.setCommandListener(listener);
    showAlert(confirmation);
    }

    private void showAlert(String title, String text) {
    alert.setTitle(title);
    alert.setString(text);
    alert.setType(AlertType.INFO);
    showAlert(alert);
    }

    void showError(Throwable t) {
    String message = t.getMessage();
    if (message != null && message.length() > 0) {
    showError(message);
    } else {
    showError(t.toString());
    }
    }

    void showError(String message) {
    alert.setTitle("Error");
    alert.setString(message);
    alert.setType(AlertType.ERROR);
    showAlert(alert);
    }

    private void showAlert(Alert alert) {
    Display display = Display.getDisplay(this);
    display.setCurrent(alert, canvas);
    }

    void barcodeAction(ParsedResult result) {
    ParsedResultType type = result.getType();
    if (type.equals(ParsedResultType.URI)) {
    String uri = ((URIParsedResult) result).getURI();
    showOpenURL("Open Web Page?", uri, uri);
    } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
    EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
    showOpenURL("Compose E-mail?", emailResult.getEmailAddress(), emailResult.getMailtoURI());
    } else if (type.equals(ParsedResultType.SMS)) {
    SMSParsedResult smsResult = (SMSParsedResult) result;
    showOpenURL("Compose SMS?", smsResult.getNumbers()[0], smsResult.getSMSURI());
    } else if (type.equals(ParsedResultType.PRODUCT)) {
    ProductParsedResult productResult = (ProductParsedResult) result;
    String uri = "http://www.google.com/m/products?q=" +
    productResult.getNormalizedProductID() + "&source=zxing";
    showOpenURL("Look Up Barcode Online?", productResult.getProductID(), uri);
    } else if (type.equals(ParsedResultType.TEL)) {
    TelParsedResult telResult = (TelParsedResult) result;
    showOpenURL("Dial Number?", telResult.getNumber(), telResult.getTelURI());
    } else {
    showAlert("Barcode Detected", result.getDisplayResult());
    }
    }

    void itemRequest() {
    ParsedResult result = (ParsedResult) resultHistory.elementAt(history.getSelectedIndex());
    barcodeAction(result);
    }

    void handleDecodedText(Result theResult) {
    ParsedResult result = ResultParser.parseResult(theResult);
    String resultString = result.toString();
    int i = 0;
    while (i < resultHistory.size()) {
    if (resultString.equals(resultHistory.elementAt(i).toString())) {
    break;
    }
    i++;
    }
    if (i == resultHistory.size()) {
    resultHistory.addElement(result);
    history.append(result.getDisplayResult(), null);
    }
    barcodeAction(result);
    }

    }

  2. #2
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    Hi nayal_genext,

    error message means no displayable(Canvas, Form) is currently set to display. add Display.getDisplay(this).setCurrent(videoControl); at before end of startApp() method might work for you.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    32

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    When I place this statement in startApp()isplay.getDisplay(this).setCurrent(videoControl);

    I am getting this error:The method setCurrent(Displayable) in the type Display is not applicable for the arguments
    (VideoControl)




    Quote Originally Posted by bandarap View Post
    Hi nayal_genext,

    error message means no displayable(Canvas, Form) is currently set to display. add Display.getDisplay(this).setCurrent(videoControl); at before end of startApp() method might work for you.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    Re: Problem in integrating zxing to j2me for nokia mobile paltform


  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    32

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    I have cross posted this on another forums because I was not able to get reply here for this question.
    If you can solve my problem please let me know


  6. #6
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    Hi nayal_genext ,

    I think resource(image) is not exited in your project. you load the image very beginning with the following call Image image = Image.createImage("/res/zxing-icon.png");

    make sure that res directory is created and zxing-icon.png is presented in that

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    32

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    I have create the Midlet project in Eclipse and the res directory is there in the project with zxing-icon.png file

    Quote Originally Posted by bandarap View Post
    Hi nayal_genext ,

    I think resource(image) is not exited in your project. you load the image very beginning with the following call Image image = Image.createImage("/res/zxing-icon.png");

    make sure that res directory is created and zxing-icon.png is presented in that

  8. #8
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: Problem in integrating zxing to j2me for nokia mobile paltform

    forward IOException and MediaException to console. something like below in the catch blocks
    System.out.println("zxing midlet output "+ioe.toString());
    System.out.println("zxing midlet output "+me.toString());


    and after that post the results back here

Similar Threads

  1. ZXing fails on Nokia N97
    By soenkek in forum Mobile Java Tools & SDKs
    Replies: 8
    Last Post: 2011-04-01, 09:24
  2. Integrating Mobile Dictionary
    By mohitrb1 in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2010-02-18, 18:37
  3. Problem integrating j2me polish with NetBeans 6.1
    By raselbd in forum Mobile Java General
    Replies: 2
    Last Post: 2008-08-25, 05:37
  4. integrating xml with J2ME
    By yafy in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-04-30, 08:58
  5. Integrating Netbeans IDE with Nokia 3650 J2ME SKD
    By fparri in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2003-09-07, 12:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •