javajava-memidpj2mepolishmmapi

Unable to capture picture using camera in J2ME Polish?


I am developing a Mobile Application in J2ME. Now I am converting it into J2ME Polish. In my application, I capture a picture using camera in mobile phone. It works fine in J2ME. But it does not work fine in J2ME Polish. I cannot resolve it.

The code snippet given below

import javax.microedition.lcdui.Canvas;
import javax.microedition.media.control.VideoControl;
//...

public class VideoCanvas extends Canvas {
  //  private VideoMIDlet midlet;
   // Form frm

 Form frm=null;

    public VideoCanvas(VideoControl videoControl) {     

        int width = getWidth();
        int height = getHeight();
       // this.midlet = midlet;

        //videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);

        //Canvas canvas = StyleSheet.currentScreen;
        //canvas = MasterCanvas.instance;



        videoControl.initDisplayMode( VideoControl.USE_DIRECT_VIDEO,this);

        try {
            videoControl.setDisplayLocation(2, 2);
            videoControl.setDisplaySize(width - 4, height - 4);
        } catch (MediaException me) {}
        videoControl.setVisible(true);



    }

    public VideoCanvas(VideoControl videoControl,Form ff) {     

     frm=ff;
        int width = getWidth();
        int height = getHeight();
       // this.midlet = midlet;

        Ticker ticker=new Ticker("B4 video controll init");
        frm.setTicker(ticker);

        //Canvas canvas = StyleSheet.currentScreen;         




       videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);

        ticker=new Ticker("after video controll init");
        frm.setTicker(ticker);

        try {
            videoControl.setDisplayLocation(2, 2);
            videoControl.setDisplaySize(width - 4, height - 4);
        } catch (MediaException me) {}
        videoControl.setVisible(true);



         ticker=new Ticker("Device not supported");
         frm.setTicker(ticker);


    }

    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        g.setColor(0x00ff00);
        g.drawRect(0, 0, width - 1, height - 1);
        g.drawRect(1, 1, width - 3, height - 3);
    }

}

In normal j2me the above code works correctly. But in j2me polish videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this) here this refers to VideoCanvas (which extends from javax.microedition.lcdui.Canvas). But it throws an "IllegalArgumentException - container should be canvas" like that. How to solve the issue?


Solution

  • The Display class is different in J2ME & J2ME Polish. I believe you are getting this error because of Display class only.

    Change your Display class to Polish's library & your problem will be solved.