×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Question Image Could not be displayed in the Mobile

    I am creating an Application which displays an image in the Emulator ..It works fine in the Emulator but when i create a Jar file and test it in mobile its not displaying ...

    I wont get any error message in Jar File... I am using Eclipse IDE and Sun Java Wireless Toolkit....

    In Jar File we get only the Alert text and not the image...Please help me out..
    I have tried Nokia s40 and s60 mobile phones ..

    Here is the Code

    package com;

    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;

    public class AlertExample extends MIDlet implements CommandListener{
    private Display display;
    public Form form;
    private Command ok,cancel,done;
    private Image img, imge, img2;
    private CanvasString canvas;


    public AlertExample() {
    form = new Form("Info Transmit");
    cancel = new Command("Cancel", Command.CANCEL, 2);
    ok = new Command("OK", Command.OK, 2);
    canvas = new CanvasString();
    try{
    img = Image.createImage("/logo.jpg");
    imge = Image.createImage("/alert.jpg");
    img2 = Image.createImage("/Logo1.jpg");
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
    }

    public void startApp() {
    display = Display.getDisplay(this);
    try{form.append(img);}catch(Exception e){}
    canvas.addCommand(cancel);
    canvas.addCommand(ok);
    canvas.setCommandListener(this);
    try
    {
    new Thread().run();
    {
    Alert success = new Alert("OK", "Alert Message Here!",img,AlertType.INFO);
    success.setTimeout(5000);
    success.setImage(img2);
    display.setCurrent(success);
    }
    Thread.sleep(5000);
    display.setCurrent(canvas);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }

    public void showMsg(){
    Alert success = new Alert("OK", "Alert Message Here!",
    img2, AlertType.INFO);

    success.setTimeout(5000);
    success.setImage(img2);
    display.setCurrent(success, form);
    }

    public void tryAgain() {
    Alert error = new Alert("Cancel", "Alert Message Here!", imge, AlertType.INFO);

    error.setTimeout(5000);
    error.setImage(imge);
    display.setCurrent(error, form);
    }

    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("Cancel")) {
    tryAgain();
    } else if(label.equals("OK")) {
    showMsg();
    }
    }
    }
    class CanvasString extends Canvas {
    boolean string = true;
    void toggleString() {
    string = !string;
    repaint();
    }

    public void paint(Graphics g) {
    g.setColor(0xccff66);
    g.fillRect(0, 0, getWidth(), getHeight());

    if(string) {
    Font font = g.getFont();
    int fontHeight = font.getHeight();
    int fontWidth = font.stringWidth("This is the Toggle Message");
    g.setColor(223, 0, 112);
    g.setFont(font);

    }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Image Could not be displayed in the Mobile

    I can see you are reading 3 images from the JAR

    img = Image.createImage("/logo.jpg");
    imge = Image.createImage("/alert.jpg");
    img2 = Image.createImage("/Logo1.jpg");

    Which of these are not able to display in the real device.

    If all these are visible on emulator, but 1 or more not visible on the device after jar is created and deployed, then please check the image file names and its extentions - they are case senstive for devices but work on emulator


    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Re: Image Could not be displayed in the Mobile

    yea i checked that....but even after that i am not getting any images in my mobile....... same thing happens when i run the jad file created in the system.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Image Could not be displayed in the Mobile

    PHP Code:
    try{
    img Image.createImage("/logo.jpg");
    imge Image.createImage("/alert.jpg");
    img2 Image.createImage("/Logo1.jpg");
    }catch(
    Exception e){
    // Put an Alrt here and see if this alert is shown ?
    System.out.println(e.getMessage());

    Read each image in seperate try/catch block, so that exception in reading one may not effect the other files, and atleast one is visible.

    I still feel the problem is with path/name/extenstion of these files -- they are case Senstive for example logo.jpg in code is not same as logo.JPG in res folder, check again. Even the packaged jar will have this issue when run in emulator.

    thanks,
    ~Amitabh

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Re: Image Could not be displayed in the Mobile

    I hav pasted the images in src folder before creating jar file.....i placed an alert in catch block as u hav said...but still the same problem continues

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Image Could not be displayed in the Mobile

    Are you getting the alerts ? All files are not displaying ? You may need to place the images in res folder, let them be an src also and try... did you check the full name of files and path for case senstivity ?

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Smile Re: Image Could not be displayed in the Mobile

    Thanks a lot im2amit.....i got the images after placing the images in res folder

Similar Threads

  1. SVGImage and viewPort: image is not displayed in phon (fine in emulator)
    By thehappycoder in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2009-03-08, 13:45
  2. Replies: 9
    Last Post: 2007-03-29, 11:17
  3. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  4. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

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