Hi Gary,

I'm using a stable version afaik - poi-3.7-20101029.jar.

As I mentioned in a previous post (before I saw your post), I found a POI file in my current directory, and after removing that, I ran into other issues. Once those were taken care of, AND I added your fix, the program compiled.


I've started a new thread with a new problem I'm having -- actually running it :-)

Peter Dow*/
Dow Software Services, Inc.
909 793-9050
pdow@xxxxxxxxxxxxxxx <mailto:pdow@xxxxxxxxxxxxxxx> /

On 7/18/2011 5:39 PM, Gary L Peskin wrote:
Hi, Dan and Peter --

You don't need to import java.lang.Integer. Each compilation unit acts as
if an

import java.lang.*;

statement is included at the beginning of the compilation unit immediately
after any package statement. (JLS 7.5.5).

All recent compilers (starting with Java 5) support autoboxing. The int
will automatically be converted to an Integer. See JLS, 5.3, and

The problem here is that only beta POI versions of getIndexHash return a
typed Map<Integer, HSSFColor>. Production POI releases return a Hashtable.
Therefore, the return value from the getIndexHash().get(xxx) method needs
the (HSSFColor) cast unless Peter is working with a beta version.


-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-
bounces@xxxxxxxxxxxx] On Behalf Of Dan Kimmel
Sent: Monday, July 18, 2011 2:17 PM
To: Java Programming on and around the IBM i
Subject: RE: Incompatible types error from getIndexHash()

The java object of type Integer is different than the primitive int.
HSSFFont.getColor() actually returns a short, but java will
automatically cast short to int. The Map object returned by
HSSFColor.getIndexHash() is indexed by Integer. Should go something like
below. If you're using a recent build of POI that supports generic
types, the value of the hash is already declared as HSSFColor, so it
doesn't need to be cast.

HSSFColor color =

You will wind up also with

import java.lang.Integer

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-
bounces@xxxxxxxxxxxx] On Behalf Of Peter Dow
Sent: Monday, July 18, 2011 2:16 PM
To: Java Programming on and around the iSeries / AS400
Subject: Incompatible types error from getIndexHash()

IANAJP (I am not a Java programmer), so please don't expect much, i.e.
it may be a totally obvious error.

I get the following error when compiling a java program I'm trying to
use to figure out how to get the color of text in a cell.

testjava.java:33: incompatible types
found : java.lang.Object
required: org.apache.poi.hssf.util.HSSFColor
HSSFColor color = HSSFColor.getIndexHash().get(colorIndex);
1 error

Here's the entire program:

import java.io.*;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class testjava {

public static void main () {

FileInputStream in = new FileInputStream("/home/pdow/test.xls");
POIFSFileSystem fs = new POIFSFileSystem(in);
HSSFWorkbook wb = new HSSFWorkbook(fs);

// The following code is from this thread:

HSSFRichTextString str =
for(int i = 0; i< str.numFormattingRuns(); i++){
short fontIndex = str.getFontOfFormattingRun(i);
HSSFFont font = wb.getFontAt(fontIndex);
int colorIndex = font.getColor();
HSSFColor color = HSSFColor.getIndexHash().get(colorIndex);

I'm hoping it's something totally obvious to someone!

Peter Dow*/
Dow Software Services, Inc.
909 793-9050


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.