Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Display.getColor() returns incorrect values in Series 40 2nd Edition (Known Issue)

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Tested with
Devices(s): All
Created: User:Technical writer 1 (10 Feb 2009)
Last edited: hamishwillee (09 Aug 2013)



Display.getColor() returns incorrect values in Series 40 devices.


According to the MIDP specifications, getColor(int colorSpecifier) should return an integer value of one of the colours from the high-level user interface colour scheme, in the form 0x00RRGGBB based on the colorSpecifier passed in.

However, in Series 40 devices, the method returns the colour value in the incorrect form 0xFFRRGGBB.

How to reproduce

The described problem can be reproduced by using the following code:

 import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class GetColor_Test extends MIDlet implements CommandListener {
private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 1);
private Display display;
public GetColor_Test() {
display = Display.getDisplay(this);
protected void startApp() {
int backgroundColour = display.getColor(Display.COLOR_BACKGROUND);
int foregroundColour = display.getColor(Display.COLOR_FOREGROUND);
int highlightBackgroundColour = display.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND);
int highlightForegroundColour = display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND);
int borderColour = display.getColor(Display.COLOR_BORDER);
int highlightBorderColour = display.getColor(Display.COLOR_HIGHLIGHTED_BORDER);
Form mainForm = new Form("GetColor Test");
mainForm.append("The reported colours should have the format " +
"0x00RRGGBB, where RR, GG and BB are the hex values " +
"for the red, green and blue components of the colour.\n");
mainForm.append("Background colour: " + convertToHexString(backgroundColour));
mainForm.append("Foreground colour: " + convertToHexString(foregroundColour));
mainForm.append("Highlight background colour: " + convertToHexString(highlightBackgroundColour));
mainForm.append("Highlight foreground colour: " + convertToHexString(highlightForegroundColour));
mainForm.append("Border colour: " + convertToHexString(borderColour));
mainForm.append("Highlight border colour: " + convertToHexString(highlightBorderColour));
protected void pauseApp() {
protected void destroyApp(boolean arg0) {
private String convertToHexString(int i) {
String string = Integer.toHexString(i);
string = string.toUpperCase();
while (string.length() < 8) {
string = "0" + string;
return "0x" + string + "\n";
public void commandAction(Command c, Displayable d) {
if (c == CMD_EXIT) {


No solution.

This page was last modified on 9 August 2013, at 04:20.
23 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.