You Are Here:

Community: Developer Discussion Boards

#1 Old put an image in MIDlet - 2004-05-25, 09:21

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
Hi all,

how can we add an image (formatted in PNG) into our MIDlet program?
Where do we have to put the image? Is it in the same directory or file than the .java program?
Thanks before for the respons.
Reply With Quote

#2 Old 2004-05-25, 10:50

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
You can put it anywhere you want as long as it get's packaged in the jar, and you use the correct path to load it (ie, if it's in the "res" directory of the jar you load it with "/res/image.png").
What files or directories find their way into the jar depends on the development environment.

shmoove
Reply With Quote

#3 Old beginner..... - 2004-06-01, 10:00

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
i'm a beginner in this field. i started to make a Midlet's application since a month ago.

So, can you help me step by step how can i put an image in my MIDlet. have u any example code for that?

thx b4...
Reply With Quote

#4 Old 2004-06-01, 16:26

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
The code is:
Code:
try {
  myImage = Image.createImage(filename);
}
catch (Exception e) {
}
Where exactly you put this image depends on how your environment is set up. How are you building your MIDlets?

shmoove
Reply With Quote

#5 Old 2004-06-02, 15:13

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
i develop my application using J2ME WTK 2.1.

my Midlet program (.java) is in the src directory
while the image " coque1.png (80x77 pixels; 1,94 kB) " is separated in res directory.

those 2 directories positioned under the same root directory.


here is the extract of the program
=========================================
public void testList () {
choose = new List("Choose items", List.MULTIPLE);
choose.setTicker(new Ticker("Testing List"));
choose.addCommand (backCommand);
choose.setCommandListener(this);

try {
image = Image.createImage("/res/coque1.png");
}

catch (Exception e) {
}

choose.append("Item 1 ", image);
choose.append("Item 2 ", null);
choose.append("Item 3 ", null);
display.setCurrent(choose);
currentMenu = "list";
}
============================================

it compiled and runned well but there was no image appears in the Nokia S40 emulator's screen.

u have any idea why did the image don't appear?

thanks 4 ur help.


-ash-
Reply With Quote

#6 Old 2004-06-02, 15:35

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
It's been a while since I messed around with the Wireless Toolkit, but if memory serves me right, it packages the images in the project's "res" folder under the root directory of the jar. You can test this easily by opening up the jar it creates (using WinZip, or WinRAR, or the zip utility of your choice), and checking to see what is the path to the image within the jar.

If my suspicion is correct (and the image is being packaged in the root directory of the jar), then you can load the image with:
Code:
image = Image.createImage("/coque1.png");
shmoove
Reply With Quote

#7 Old 2004-06-02, 17:05

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
code :
=============================================
public void testAlert2() {
try {
//myImage = Image.createImage("/TestGUI/res/coque1.png");
//myImage = Image.createImage("/res/coque1.png");
myImage = Image.createImage("/coque1.png");
}

catch (Exception e) {
}

alert = new Alert ("Alert Image");
alert.setImage(myImage);
alert.setTimeout(Alert.FOREVER);
alert.addCommand(backCommand);
display.setCurrent(alert);
currentMenu="alert";
}
==============================================


i've tried all of the three possibility above but nothing appears.
it's, however, weird.

have any further idea?


-ash-
Reply With Quote

#8 Old 2004-06-03, 10:47

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
in all three cases above, J2ME WTK2.1 shows me the message :

======================
java.lang.NullPointerException
======================

i read in the documentation that it was caused by the null photo ressource.

i don't understand this becoz i've rightly put my image (coque1.png) which values 12 KB and 80 x 77 pixels
but still no image appear.

any further idea?

thx
-ash-
Reply With Quote

#9 Old 2004-06-03, 11:03

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
Have you tried opening the jar file and checking what's the path to the image in the jar (or if it is in there at all) ?

shmoove
Reply With Quote

#10 Old 2004-06-04, 10:19

Join Date: May 2004
Posts: 22
Location: La Rochelle
ash_putra
Offline
Registered User
thanks shmoove, it worked.

finally, it was placed under the root directory of the jar file.

code
==============================================
try {
myImage = Image.createImage("/coque1.png");
}

catch {
}
==============================================


A new problem comes now that my application executed well using
all emulators in J2ME WTK 2.1 except the Nokia s40 dp2.0.
i mean the image appeared fine.

but while launching the application using
Nokia S40 DP2.0 the messages below have appeared.

messages of exception
==============================================
Exception: java/io/IOException

at com.sun.cldc.io.ResourceInputStream.<init>(+14)

at java.lang.Class.getResourceAsStream(+83)

at javax.microedition.lcdui.Image.createImage(+24)

at com.nokia.mid.impl.isa.ui.MIDletRTInfo.setIcon(+9)

at com.nokia.mid.impl.isa.ui.MIDletRTInfo.<init>(+113)

at com.nokia.mid.impl.isa.ui.MIDletManager.s_loadMIDletSuite(+57)

at com.nokia.mid.impl.isa.ui.MIDletManager.main(+80)


Exception: java/io/IOException

at javax.microedition.lcdui.Image.createImage(+55)

at com.nokia.mid.impl.isa.ui.MIDletRTInfo.setIcon(+9)

at com.nokia.mid.impl.isa.ui.MIDletRTInfo.<init>(+113)

at com.nokia.mid.impl.isa.ui.MIDletManager.s_loadMIDletSuite(+57)

at com.nokia.mid.impl.isa.ui.MIDletManager.main(+80)


Exception: java/lang/ClassNotFoundException

at com.nokia.mid.impl.isa.ui.MIDletRTInfo.<init>(+120)

at com.nokia.mid.impl.isa.ui.MIDletManager.s_loadMIDletSuite(+57)

at com.nokia.mid.impl.isa.ui.MIDletManager.main(+80)

==============================================


have any idea why it happened?
they (nokia and provided emulators from J2ME WTK 2.1)
dispose the same API right??

thx before.
Reply With Quote

#11 Old Smile Re: put an image in MIDlet - 2008-08-12, 22:01

Join Date: Aug 2008
Posts: 1
bikky
Offline
Registered User
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.IOException;

public class ImageItemDemo extends MIDlet implements CommandListener
{
private Display display;
private Command exit;
private ImageItem imageItem;
private Form frmMain;

public ImageItemDemo() throws IOException
{
display=Display.getDisplay(this);
frmMain=new Form("\t\t\t--Apple--");

Image image = Image.createImage("/a.png");
imageItem = new ImageItem("Apple Drive",image,ImageItem.LAYOUT_CENTER,"Image not found");
frmMain.append(imageItem);
exit=new Command("Exit",Command.EXIT,1);

frmMain.addCommand(exit);
frmMain.setCommandListener(this);

}
public void startApp()
{
display.setCurrent(frmMain);
}

public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command c, Displayable s)
{
if(c==exit)
{
destroyApp(true);
notifyDestroyed();
}
}
}


This is the full code for Display any type of image in MIDlet....
Drag the image into the "src> package" tab in the window in package explorer in Eclipse IDE...

U ll get the display...
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d134434X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ