Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Contributor
Posts: 8
Registered: ‎01-21-2014
My Device: 9800
My Carrier: my Self

i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

public class Images extends MainScreen {

int mImgWidth = 80;
int mImgHeight = 80;
int mImgMargin = 10;

String fileNames[] = { "1.png", "2.png", "3.png", "4.png", "5.png",
"6.png", "7.png" };
EncodedImage[] mImages;

public Images() {
super();
System.out.println("hello");
prepareImages();
}

private void prepareImages() {
mImages = new EncodedImage[fileNames.length];
for (int i = 0; i < fileNames.length; i++) {
EncodedImage image = EncodedImage
.getEncodedImageResource(fileNames[i]);
mImages[i] = sizeImage(image, mImgWidth, mImgHeight);
}
}

protected void paint(Graphics graphics) {
paintImages(graphics);
super.paint(graphics);
}

private void paintImages(Graphics graphics) {
int scrWidth = Display.getWidth();
int columns = scrWidth / (mImgWidth + 2 * mImgMargin);
int rows = mImages.length / columns
+ (mImages.length % columns > 0 ? 1 : 0);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
int posX = j * (mImgWidth + 2 * mImgMargin) + mImgMargin;
int posY = i * (mImgHeight + 2 * mImgMargin) + mImgMargin;
EncodedImage image = mImages[i * columns + j];
graphics.drawImage(posX, posY, mImgWidth, mImgHeight,
image, 0, 0, 0);
}
}
}

public EncodedImage sizeImage(EncodedImage image, int width,
int height) {
EncodedImage result = null;

int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());

int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);

int scaleXFixed32 = Fixed32.div(currentWidthFixed32,
requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32,
requiredHeightFixed32);

result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return result;
}
}

New Contributor
Posts: 8
Registered: ‎01-21-2014
My Device: 9800
My Carrier: my Self

Re: i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

Array Index Out of Bounds Exception
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

arrays do not resize. initialize mImages with the required size or use a dynamic structure (like vector).

using a debugger should show you exactly where the exception occurs.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

And I suspect your problem is here:

 

EncodedImage image = mImages[i * columns + j] ...

 

I think you need to check that the index you are accessing in mImages actually exists.

Highlighted
New Contributor
Posts: 8
Registered: ‎01-21-2014
My Device: 9800
My Carrier: my Self

Re: i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

still i don't solve it, help me bro

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: i want to show 7 images in screen ,Every image size should be same if i rotate mobile that will adjust

Have you debugged as Simon suggested?  Which statement is throwing the Exception?