【问题标题】:Guava's HashBasedTable cellSet()Guava 的 HashBasedTable cellSet()
【发布时间】:2012-09-01 03:48:52
【问题描述】:

我有以下设置。

Table<Integer, Integer, Float> store = HashBasedTable.create();

int i = 0, j = 0;

for (List<String> stack_i : stacks) {
  j = 0;

  for (String entry_j : stack_i) {
    Float alpha = doSomeMagic(entry_j, token);
    if (alpha != null)
      store.put(i, j, alpha);
    j++;
  }
  i++;
}

if (store.cellSet().size() > 0) {
  for (Table.Cell<Integer, Integer, Float> cell : store.cellSet()) {
    if (cell.getValue() > max) {
      max = cell.getValue();
      maxchainIndex = cell.getRowKey();
    }
  }
}

我遇到的问题是我收到以下 JVM 错误:

严重:java.lang.IllegalAccessError:试图访问方法 com.google.common.collect.Iterators.emptyModifiableIterator()Ljava/util/Iterator;来自类 com.google.common.collect.StandardTable$CellIterator 在 com.google.common.collect.StandardTable$CellIterator.(StandardTable.java:310) 在 com.google.common.collect.StandardTable$CellIterator.(StandardTable.java:306) 在 com.google.common.collect.StandardTable$CellSet.iterator(StandardTable.java:280)

错误发生在行

for(Table.Cell<Integer,Integer,Float> cell:store.cellSet())

我看不出我在这里做错了什么。我查过了,店里至少有 1 件商品。

【问题讨论】:

  • 您能否提供一个代码示例,我们可以自己编译和运行以重现错误?

标签: java guava


【解决方案1】:

对我来说看起来不错,我能够成功运行以下命令。你能在没有任何额外元素的情况下运行它来消除与 for 循环无关的任何有趣的事情吗?

Table<Integer, Integer, Double> abc = HashBasedTable.create();
abc.put(1, 1, 10d);
for (Table.Cell<Integer, Integer, Double> x : abc.cellSet()) {
    System.out.println(x.toString());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多