ERROR:
对IndexOutOfBoundsException的引用不明确,com.sun.star.lang中的类com.sun.star.lang.IndexOutOfBoundsException和java.lang中的类java.lang.IndexOutOfBoundsException匹配
CODE:
public void insertIntoCell(int CellX, int CellY, String theValue,
XSpreadsheet TT1,
String flag) throws IndexOutOfBoundsException {
XCell oCell = null;
oCell = TT1.getCellByPosition(CellX, CellY);
if (flag.equals("V")) {
oCell.setValue((new Float(theValue)).floatValue());
} else {
if (theValue!=null && theValue.length()>0 && theValue.length()!=0) {
oCell.setFormula("'"+(String)theValue.toString());
} else {
oCell.setFormula((String)theValue.toString());
}
}
}
答案 0 :(得分:5)
完全限定例外类型。
public void insertIntoCell.. throws com.sun.star.lang.IndexOutOfBoundsException {
}
我在这里假设您不打算抛出java.lang.IndexOutOfBoundsException
,这是一个未经检查的RuntimeException
,但我可能是错的。
您也可以使用single-type import declaration代替:
import com.sun.star.lang.IndexOutOfBoundsException;
//...
public void insertIntoCell.... throws IndexOutOfBoundsException {
}
但这可能会导致管道混乱。
答案 1 :(得分:4)
类IndexOutOfBoundsException
在(隐式)导入中出现过多次。您需要将导入重新组织为更具体(即不要使用import com.sun.star.lang.*
而是使用import com.sun.star.lang.SomeClassName
,如果您使用的是像Eclipse这样的IDE,它可以自动为您执行此操作),或者改为使用完全限定类名。即包括包裹,例如
throws java.lang.IndexOutOfBoundsException
而不是
throws IndexOutOfBoundsException
也就是说,com.sun.*
或sun.*
上的导入被认为是不好的做法,因为那些是未记录的Sun类,它们可能会发生变化而无法在非Sun JVM上运行。即使Sun本身也建议不要在自己的代码中导入/使用这些类。
答案 2 :(得分:1)
IndexOutOfBoundsException是不明确的,因为在两个不同的包(com.sun.star.lang和java.lang)中有两个名为IndexOutOfBoundsException的类。您需要通过为IndexOutOfBoundsException添加正确的包名称来告诉编译器您的意思。
答案 3 :(得分:0)
@BalusC和@polygenelubricants答案都是现货。
我只想指出,这说明了当某人定义一个与java.lang
中的类同名的类或者(在较小程度上)其中一个广泛使用的类时可能出现的问题。您可能长期遇到的其他示例包括java.util.Date
与java.sql.Date
和java.util.List
与java.awt.List
。