×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    This concerns using the Series 40 Emulator with the Eclipse Pulsar Helios IDE. I receive a "cannot read /airplane.png" message wile testing the below code, which came from this URL: http://www.roseindia.net/j2me/list-image.shtml.

    I made a small PNG file named airplane.png, and while trying to get it to be read, I placed a copy of it in every folder associated with this particular project.

    I do not have a .jar file. If I need one, does anyone know how to generate one with Eclipse Pulsar Helios?

    Code:
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    public class ListImage extends MIDlet implements CommandListener{
      private Display display;
      private List list;
      private Command exit, next;
      private Image car, airplane, hotel, mobile, cartoon;
      String[] stringElements = {"Aero plane", "Car", "Hotel", "Mobile"};
      
      public ListImage(){
      try{
      airplane = Image.createImage("/airplane.png");
      car = Image.createImage("/car1.png");
      hotel = Image.createImage("/hotel1.png");
      mobile = Image.createImage("/mobile_ico.png");
      cartoon = Image.createImage("/cartoon.png");
      }catch(Exception e){
      System.err.println(e.getMessage());
      }
      }
    
      public void startApp() {
      display = Display.getDisplay(this);
      Image[] imageElements = {airplane, car, hotel, mobile};
      list = new List("List + Image", List.IMPLICIT, 
    stringElements, imageElements);
    
      next = new Command("Select", Command.SCREEN, 0);
      exit = new Command("Exit", Command.EXIT, 0);
      list.addCommand(next);
      list.addCommand(exit);
      list.setCommandListener(this);
      display.setCurrent(list);
      }
    
      public void pauseApp() {}
    
      public void destroyApp(boolean unconditional){
      notifyDestroyed();
      }
    
      public void commandAction(Command c, Displayable s){
      int index = list.getSelectedIndex();
      if (c == next || c == List.SELECT_COMMAND) {
      Alert alert = new Alert("Selected", "You have selected: 
    " + list.getString(index) 
    
      + ".", cartoon, AlertType.INFO);
      display.setCurrent(alert, list);
      } else if(c == exit){
      destroyApp(true);
      }
      }
    }

  2. #2
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Quote Originally Posted by John_123 View Post
    This concerns using the Series 40 Emulator with the Eclipse Pulsar Helios IDE. I receive a "cannot read /airplane.png" message wile testing the below code, which came from this URL: http://www.roseindia.net/j2me/list-image.shtml.

    I made a small PNG file named airplane.png, and while trying to get it to be read, I placed a copy of it in every folder associated with this particular project.

    I do not have a .jar file. If I need one, does anyone know how to generate one with Eclipse Pulsar Helios?

    Code:
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    
    public class ListImage extends MIDlet implements CommandListener{
      private Display display;
      private List list;
      private Command exit, next;
      private Image car, airplane, hotel, mobile, cartoon;
      String[] stringElements = {"Aero plane", "Car", "Hotel", "Mobile"};
      
      public ListImage(){
      try{
      airplane = Image.createImage("/airplane.png");
      car = Image.createImage("/car1.png");
      hotel = Image.createImage("/hotel1.png");
      mobile = Image.createImage("/mobile_ico.png");
      cartoon = Image.createImage("/cartoon.png");
      }catch(Exception e){
      System.err.println(e.getMessage());
      }
      }
    
      public void startApp() {
      display = Display.getDisplay(this);
      Image[] imageElements = {airplane, car, hotel, mobile};
      list = new List("List + Image", List.IMPLICIT, 
    stringElements, imageElements);
    
      next = new Command("Select", Command.SCREEN, 0);
      exit = new Command("Exit", Command.EXIT, 0);
      list.addCommand(next);
      list.addCommand(exit);
      list.setCommandListener(this);
      display.setCurrent(list);
      }
    
      public void pauseApp() {}
    
      public void destroyApp(boolean unconditional){
      notifyDestroyed();
      }
    
      public void commandAction(Command c, Displayable s){
      int index = list.getSelectedIndex();
      if (c == next || c == List.SELECT_COMMAND) {
      Alert alert = new Alert("Selected", "You have selected: 
    " + list.getString(index) 
    
      + ".", cartoon, AlertType.INFO);
      display.setCurrent(alert, list);
      } else if(c == exit){
      destroyApp(true);
      }
      }
    }
    Try to create image in startApp method instead of in constructure

  3. #3
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Thank you for the recommendation, pradip7. The same message appears after moving the code for creating the images to the startApp method.

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Hello John_123,

    have you tried to create a res folder for the PNG images in the project?

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  5. #5
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Hi, r2j7. Eclipse had created a "res" folder already. I double-checked to make sure that the image file was in the folder, and tried again. The same error message appeared.

    Below is the line of code:

    Code:
    airplane = Image.createImage("/res/airplane.png");
    I then removed the forward slash that is in front of "res", with the new line of code looking like this:

    Code:
    airplane = Image.createImage("res/airplane.png");
    That didn't work either. (I then put the forward slash back, lest I forget to do so later.)

    I appreciate you taking the time to follow up about this.

    One moment...I'm going to check the spelling of the file name, including capitalization, and compare it to the code. I'll check back in here after I do so....

  6. #6
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    I changed the file name from the mixed caps "airplane.PNG" to the all lowercase "airplane.png", but I received the same error message again.

  7. #7
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Quote Originally Posted by John_123 View Post
    I changed the file name from the mixed caps "airplane.PNG" to the all lowercase "airplane.png", but I received the same error message again.
    Try with Following-
    inputStream=MIDLet.getClass.getResourceAsStreame(resName); method and pass that inputStraem into the Image .createImage(inputStream);
    Regards,
    Pradip

  8. #8
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Thank you for the information, Pradip. I apologize that I lack the knowledge as to how to implement the inputStream code. Do I need to declare the inputStream? Also, do I need to declare resName and set it equal to "/res/airplane.png"?

  9. #9
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Quote Originally Posted by John_123 View Post
    Thank you for the information, Pradip. I apologize that I lack the knowledge as to how to implement the inputStream code. Do I need to declare the inputStream? Also, do I need to declare resName and set it equal to "/res/airplane.png"?
    Yes,you have to declear inputStream object and resource string also (As you wrote resource string),try in both case with /res and wothout /res and also with only file name becouse I am working on netbeans,i dont know about eclips thats why.
    Regards,
    Pradip

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

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Remember the resource name - /res/airplane.png - is case sensitive in case of real devices or simulators that work with final packaged jar --- while windows OS --- is not case sensitive for filenames.

    Check the resource file name - for character case.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  11. #11
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: "Cannot read" message when trying to display a PNG with the Series 40 Emulator.

    Thank you for the tips, Pradip and Amitabh.

Similar Threads

  1. Replies: 11
    Last Post: 2009-08-29, 09:56
  2. WS client - how to prevent display "untrusted certificate" warning message?
    By asheraslan in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-02-06, 12:53
  3. How to Read a "Chinese Text" file and display it.
    By wingfancy in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-03-18, 02:15
  4. Replies: 2
    Last Post: 1970-01-01, 02:00

Posting Permissions

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