This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java Micro Edition and the fly likes Images + String -Byte Array.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Images + String -Byte Array.." Watch "Images + String -Byte Array.." New topic

Images + String -Byte Array..

Kamlesh Ladva

Joined: Sep 16, 2008
Posts: 1
Hello guys,

I am trying to read images and strings from a byte array stored on a server using j2me..The following code does work but shows only 2 images & strings instead of the required 5..It throws a null pointer exception on the g.drawimage...line...any help would be much appreciated guys..

public void showVenues(byte[] venueList)
listOfText = new String[5];
imageList = new Image[5];
int textLength = 0;
int imageLength = 0;
int totalLength = 0;
int offset = 0;
for (int z = 0; z< 5; z++)
textLength = arr2int(venueList, totalLength);
imageLength = arr2int(venueList, totalLength+4);
listOfText[z] = new String(venueList, totalLength+8, textLength, "ASCII");
imageList[z] = Image.createImage(venueList, totalLength+8+textLength, imageLength);
totalLength += textLength + imageLength + 8;
catch(Exception uex)

public void paintVenues(Graphics g)
System.out.println("Painting venues");
g.fillRect(0, 0, getWidth(), getHeight());
for (int i = 0; i<= imageList.length; i++)
g.drawImage(imageList[i], 0, 50 * (i+1), 0);
//g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
g.drawString(listOfText[i], 50, 55 * (i+1), 0);

I agree. Here's the link:
subject: Images + String -Byte Array..
Similar Threads
B&S:db format question
Why won't this for loop work?
Graphics and JVMs
Help with snow