最近用原生hbase包开发,用到了guava包,用的版本是30.1.1-android,报了下了这个错误:
tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
原因:在MetaTableLocator中有这样一个方法(这里hbase-client使用的是1.2.5版本,2.0.0版本没有这样一个类),
public ServerName blockUntilAvailable(final ZooKeeperWatcher zkw, int replicaId,
final long timeout)
throws InterruptedException {
if (timeout < 0) throw new IllegalArgumentException();
if (zkw == null) throw new IllegalArgumentException();
//具体问题出现在这里
Stopwatch sw = new Stopwatch().start();
ServerName sn = null;
try {
while (true) {
sn = getMetaRegionLocation(zkw, replicaId);
if (sn != null || sw.elapsedMillis()
> timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
break;
}
Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
}
} finally {
sw.stop();
}
return sn;
}
再看方法中是使用的Stopwatch类无参构造没有使用访问修饰符,代码如下:
Stopwatch() {
this.ticker = Ticker.systemTicker();
}
看到这里也不用过多解释,这里的解决办法是将guava版本升级到16.0.1。
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>