Results 1 to 4 of 4
  1. #1
    agajantorayev is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default Can anyone help with Images???

    Hello everyone, I have the following code:
    Java Code:
    
    package itest;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    
    public class TravelList extends MIDlet implements CommandListener{
    
        private List mList;
        private Command mExitCommand, mNextCommand;
    
        public TravelList(){
            String [] stringElements = {"Abdyresul", "Kerim", "Agajan"};
            Image [] imageElements = {load("/abdyresul.png"), load("/kerim.png"),
            load("/agajan.png")};
    
            mList =  new List("Member Type", List.IMPLICIT, stringElements, imageElements);
            mNextCommand = new Command("Next", Command.SCREEN, 0);
            mExitCommand = new Command("EXIT", Command.EXIT, 0);
            mList.addCommand(mExitCommand);
            mList.addCommand(mNextCommand);
            mList.setCommandListener(this);
        }//constructor
    
        public void startApp() {
            Display.getDisplay(this).setCurrent(mList);
        }
    
        public void pauseApp() {
        }
    
        public void commandAction(Command c, Displayable s){
            if(c==mNextCommand || c==List.SELECT_COMMAND){
                int index = mList.getSelectedIndex();
                Alert alert = new Alert(mList.getString(index));
                Display.getDisplay(this).setCurrent(alert, s);
            }
            else if(c==mExitCommand) {
                System.out.println("Exiting");
                notifyDestroyed();
            }
        }
    
        public void destroyApp(boolean unconditional) {
        }
    
        private Image load(String name){
            Image img = null;
            try{
                img = Image.createImage(name);
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return img;
        }
    }
    I am working on Java ME SDK 3.0; My problem is that this midlet does-not load image, where do I need to put images. And there is exception:
    java.io.IOException
    - javax.microedition.lcdui.ImageDataFactory.createIm ageFromStream(), bci=8
    - javax.microedition.lcdui.ImageDataFactory.createRe sourceImageData(), bci=45
    - javax.microedition.lcdui.Image.createImage(), bci=8
    - itest.TravelList.load(), bci=3
    - itest.TravelList.<init>(), bci=42
    - java.lang.Class.newInstance(), bci=0
    - com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46
    - com.sun.midp.midlet.MIDletStateHandler.createMIDle t(), bci=66
    - com.sun.midp.midlet.MIDletStateHandler.createAndRe gisterMIDlet(), bci=17
    - com.sun.midp.midlet.MIDletStateHandler.startSuite( ), bci=27
    - com.sun.midp.main.AbstractMIDletSuiteLoader.startS uite(), bci=52
    - com.sun.midp.main.CldcMIDletSuiteLoader.startSuite (), bci=8
    - com.sun.midp.main.AbstractMIDletSuiteLoader.runMID letSuite(), bci=161
    - com.sun.midp.main.AppIsolateMIDletSuiteLoader.main (), bci=26

    Can anyone help me solve this???

  2. #2
    peter_budo is offline Member
    Join Date
    Dec 2010
    Posts
    49
    Rep Power
    0

    Default

    What I usually did was that inside "src" folder I created package for midlet "midletpack" for example and on same level created "res" folder for resources where I placed images. So then when I called for image from class I give it absolute path as "/res/image_name.png"

    Folder view
    • src
      • midletpack
        • MyMidlet.java
        • ClassOne.java
        • ClassTwo.java
      • res
        • image_one.png
        • image_two.jpg
        • mp3_one.mp3

  3. #3
    agajantorayev is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    It does not work either: Exception is :
    java.io.IOException
    - javax.microedition.lcdui.ImageDataFactory.createIm ageFromStream(), bci=8
    - javax.microedition.lcdui.ImageDataFactory.createRe sourceImageData(), bci=45
    - javax.microedition.lcdui.Image.createImage(), bci=8
    - itest.TravelList.load(), bci=3
    - itest.TravelList.<init>(), bci=51
    - java.lang.Class.newInstance(), bci=0
    - com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46
    - com.sun.midp.midlet.MIDletStateHandler.createMIDle t(), bci=66
    - com.sun.midp.midlet.MIDletStateHandler.createAndRe gisterMIDlet(), bci=17
    - com.sun.midp.midlet.MIDletStateHandler.startSuite( ), bci=27
    - com.sun.midp.main.AbstractMIDletSuiteLoader.startS uite(), bci=52
    - com.sun.midp.main.CldcMIDletSuiteLoader.startSuite (), bci=8
    - com.sun.midp.main.AbstractMIDletSuiteLoader.runMID letSuite(), bci=161
    - com.sun.midp.main.AppIsolateMIDletSuiteLoader.main (), bci=26

  4. #4
    peter_budo is offline Member
    Join Date
    Dec 2010
    Posts
    49
    Rep Power
    0

    Default

    I just run it in WTK 2.5.2 and have no problems...


    Can anyone help with Images???-list_screenshot.jpg

    In attachments you can also see my folder structure from IntelliJ IDE
    Attached Files Attached Files

Similar Threads

  1. Images
    By Witik in forum New To Java
    Replies: 7
    Last Post: 09-13-2010, 01:34 PM
  2. XML Images
    By JavaWizz in forum XML
    Replies: 1
    Last Post: 10-17-2008, 10:19 AM
  3. images
    By amith in forum AWT / Swing
    Replies: 3
    Last Post: 06-27-2008, 08:38 PM
  4. Help with images...
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 05:25 AM
  5. Images in JSP
    By Daniel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-05-2007, 06:01 AM

Posting Permissions

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