从Android中的ListView中删除最后一项时出错(Error when removing last item from ListView in Android)
我有一个带有onListItemListener的ListView,我有它所以如果你点击一个ListView项目它会删除它,但由于某种原因,如果我从列表中删除最后一项,应用程序崩溃并给我这个错误
(java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3)
有谁知道这意味着什么?
这是我的代码:
@Override protected void onListItemClick(ListView l, View v, int pos, long id) { super.onListItemClick(l, v, pos, id); adapter.remove(adapter.getItem(pos)); adapter.notifyDataSetChanged(); }
I have a ListView with a onListItemListener, I have it so if you tap a ListView Item it removes it, but for some reason if I remove the last item form the list, the app crashes and gives me this error
(java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3)
Does anyone have any idea what that means?
This is my code:
@Override protected void onListItemClick(ListView l, View v, int pos, long id) { super.onListItemClick(l, v, pos, id); adapter.remove(adapter.getItem(pos)); adapter.notifyDataSetChanged(); }
原文:https://stackoverflow.com/questions/15080557
最满意答案
我相信您要查找的术语是命名范围 (尽管它们在某些版本的Excel中的功能区的“公式”选项卡中定义)。 假设你是这个意思:
然后,Apache POI需要的关键方法是:
如果你知道范围的名称,并想要得到它所指的单元格,你就会做类似的事情
Workbook wb = WorkbookFactory.create(new File("input.xls")); Name name = wb.getName("TestRange"); System.out.println("Named Range '" + name.getNameName() + "' points to " + name.getRefersToFormula());
对于上述情况,将打印出来
Named Range 'TesRange' points to Sheet1!$A$1:$C$5
I believe that the term you are looking for is a Named Range (though they are defined in the Formula tab of the ribbon in some versions of Excel). Assuming you mean this:
Then the key methods you need from Apache POI are:
If you know the name of the range, and want to get the cells it refers to, you'd do something like
Workbook wb = WorkbookFactory.create(new File("input.xls")); Name name = wb.getName("TestRange"); System.out.println("Named Range '" + name.getNameName() + "' points to " + name.getRefersToFormula());
Which for the case above would print
Named Range 'TesRange' points to Sheet1!$A$1:$C$5
相关问答
更多-
Apache POI评估公式(Apache POI evaluate formula)[2022-10-04]
为了促进对答案的评论... 您首先需要确保您为主jar和OOXML部分使用相同版本的POI。 你的maven代码片段显示为3.7,另一个显示为3.8 beta 1。 你需要确保他们都是一样的。 (你甚至可能想要使用3.8-beta2)。 然后,使用: FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); evaluator.evaluateFormulaCell(cell); 要么: XSSFFormul ... -
使用Apache POI及其名称获取Excel公式的内容(Get Content of a Excel Formula with Apache POI and its name)[2022-10-21]
我相信您要查找的术语是命名范围 (尽管它们在某些版本的Excel中的功能区的“公式”选项卡中定义)。 假设你是这个意思: 然后,Apache POI需要的关键方法是: Workbook.getNumberOfNames() Workbook.getName(字符串) Workbook.getNameAt(INT) Workbook.createName() 如果你知道范围的名称,并想要得到它所指的单元格,你就会做类似的事情 Workbook wb = WorkbookFactory.create(new F ... -
正如@JB Nizet所说:在写回复之前设置Header。 所以你应该做的是以下几点: ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); workbook.write(byteArrayOutputStream); response.setHeader("Content-Length", "" + byteArrayOutputStream.size()); workbook.write(response.g ...
-
可以按CTRL-ALT-F9手动在Excel中强制重新评估所有公式。 这里有个诀窍让它在工作簿打开时自动运行。 将以下内容添加到您的公式中: +(NOW()*0) 例如,我的SUMPRODUCT在上面变成了 =SUMPRODUCT((DS!B:B="IN_THIS_ONLY")*(DS!D:D="New trade"))+(NOW()*0) 这工作! Excel现在重新计算我公开的特殊公式单元格。 原因是NOW()是一个易失性函数。 这里是我学习这个的地方: http : //msdn.microsof ...
-
您需要“评估”单元格以获得公式的结果。 这不是由POI自动完成的,因为它可能是一项繁重的操作,往往不是必需的。 有关详细信息,请参阅http://poi.apache.org/spreadsheet/eval.html ,基本上,您将创建一个FormulaEvaluator并为有问题的单元检索CellValue FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); ... CellValue cellVal ...
-
Apache poi Excel:基于列的整数索引创建公式(Apache poi Excel: Creating a formula based on the integer index of the column)[2021-06-17]
这只需要一点点代码: public static String columnName(int index) { StringBuilder s = new StringBuilder(); while (index >= 26) { s.insert(0, (char) ('A' + index % 26)); index = index / 26 - 1; } s.insert(0, (char) ('A' + index)); re ... -
你应该可以通过Cell样式来实现这一点,我试图将一个例子展示出来: public class SO{ public static void main(String[] args) { try { FileInputStream is = new FileInputStream(new File("D:\\Users\\user2777005\\Desktop\\bob.xlsx")); XSSFWorkbook wb = new XS ...
-
我改变了公式,在函数调用NOT(M2)周围添加括号 INT(AND(L2,NOT(M2))) ====> INT(AND(L2,(NOT(M2))))问题解决了。 I changed the formula adding parenthesis around the function call NOT(M2) INT(AND(L2,NOT(M2))) ====> INT(AND(L2,(NOT(M2)))) and the problem was solved.
-
它发现引入createConditionalFormattingRule的字符串必须是单元格坐标 ConditionalFormattingRule rule = sheetConditionalFormatting.createConditionalFormattingRule(ComparisonOperator.EQUAL, "B1"); it found out that string introduced into the createConditionalFormattingRule must ...
-
链接示例的主要问题是它将所有列命名为“Column”: ... for(int i=0; i<3; i++) { //Create column column = columns.addNewTableColumn(); column.setName("Column"); column.setId(i+1); ... 所以公式解析器不能区分它们。 但是填充表列标题并使用一个循环填充表单内容的整个 ...