Support Questions
Find answers, ask questions, and share your expertise

HBase - Using Java API to put data into Table gives error

Expert Contributor

Hi All,

I've HDP 2.4 & i'm trying to put data into HBase table using Java API, it gives error shown below,

Any ideas pls let me know. Code used to add data to the HBase table (java file attached) -> accessobjectjava.txt public Put mkPut(User u){ Put p = new Put(Bytes.toBytes(u.user)); p.add(INFO_FAMILY, USER_COL, Bytes.toBytes(u.user)); p.add(INFO_FAMILY, NAME_COL, Bytes.toBytes(u.name)); p.add(INFO_FAMILY, EMAIL_COL, Bytes.toBytes(u.email)); return p; }

public void addUser(String user, String name, String email) throws IOException{ HTableInterface users = connection.getTable(TABLE_NAME); Put p = mkPut(new User(user,name,email)); users.put(p); users.close(); } ---------------------------------ERROR ON CONSOLE--------------------------------------------------------

[root@sandbox ~]# java hbase/Exercise2/HBaseTester add kim123 kim kim@gmail.com log4j:WARN No appenders could be found for logger (org.apache.hadoop.util.Shell). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Adding user... in add user in add user, users users;hconnection-0x43cdebe p {"totalColumns":3,"families":{"info":[{"timestamp":9223372036854775807,"tag":[],"qualifier":"user","vlen":6},{"timestamp":9223372036854775807,"tag":[],"qualifier":"name","vlen":3},{"timestamp":9223372036854775807,"tag":[],"qualifier":"email","vlen":13}]},"row":"kim123"} java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:208) at org.apache.hadoop.hbase.client.ClientSmallReversedScanner.loadCache(ClientSmallReversedScanner.java:211) at org.apache.hadoop.hbase.client.ClientSmallReversedScanner.next(ClientSmallReversedScanner.java:185) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegionInMeta(ConnectionManager.java:1256) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1162) at org.apache.hadoop.hbase.client.AsyncProcess.submit(AsyncProcess.java:370) at org.apache.hadoop.hbase.client.AsyncProcess.submit(AsyncProcess.java:321) at org.apache.hadoop.hbase.client.BufferedMutatorImpl.backgroundFlushCommits(BufferedMutatorImpl.java:206) at org.apache.hadoop.hbase.client.BufferedMutatorImpl.flush(BufferedMutatorImpl.java:183) at org.apache.hadoop.hbase.client.HTable.flushCommits(HTable.java:1449) at org.apache.hadoop.hbase.client.HTable.put(HTable.java:1040) at hbase.Exercise2.AccessObject.addUser(AccessObject.java:93) at hbase.Exercise2.HBaseTester.main(HBaseTester.java:27) Caused by: java.lang.NullPointerException at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.getMetaReplicaNodes(ZooKeeperWatcher.java:399) at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:552) at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1192) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1159) at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:151) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:59) at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200) ... 12 more Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:208) at org.apache.hadoop.hbase.client.ClientSmallReversedScanner.loadCache(ClientSmallReversedScanner.java:211) at org.apache.hadoop.hbase.client.ClientSmallReversedScanner.next(ClientSmallReversedScanner.java:185) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegionInMeta(ConnectionManager.java:1256) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1162) at org.apache.hadoop.hbase.client.AsyncProcess.submit(AsyncProcess.java:370) at org.apache.hadoop.hbase.client.AsyncProcess.submit(AsyncProcess.java:321) at org.apache.hadoop.hbase.client.BufferedMutatorImpl.backgroundFlushCommits(BufferedMutatorImpl.java:206) at org.apache.hadoop.hbase.client.BufferedMutatorImpl.flush(BufferedMutatorImpl.java:183) at org.apache.hadoop.hbase.client.HTable.flushCommits(HTable.java:1449) at org.apache.hadoop.hbase.client.HTable.close(HTable.java:1485) at hbase.Exercise2.AccessObject.addUser(AccessObject.java:98) at hbase.Exercise2.HBaseTester.main(HBaseTester.java:27) Caused by: java.lang.NullPointerException at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.getMetaReplicaNodes(ZooKeeperWatcher.java:399) at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:552) at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1192) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1159) at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:151) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:59) at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200) ... 12 more

1 ACCEPTED SOLUTION

Accepted Solutions

after looking at the attached program it seems that you are not initializing the configuration object properly. you need to do something like this to create configuration object

Configuration conf =HBaseConfiguration.create();

conf.set("hbase.zookeeper.property.clientPort","2181");

conf.set("hbase.zookeeper.quorum","<hostname>");

conf.set("zookeeper.znode.parent","/hbase");

please refer this to create connection object

https://community.hortonworks.com/articles/2038/how-to-connect-to-hbase-11-using-java-apis.html

View solution in original post

2 REPLIES 2

after looking at the attached program it seems that you are not initializing the configuration object properly. you need to do something like this to create configuration object

Configuration conf =HBaseConfiguration.create();

conf.set("hbase.zookeeper.property.clientPort","2181");

conf.set("hbase.zookeeper.quorum","<hostname>");

conf.set("zookeeper.znode.parent","/hbase");

please refer this to create connection object

https://community.hortonworks.com/articles/2038/how-to-connect-to-hbase-11-using-java-apis.html

View solution in original post

Expert Contributor

@Rajkumar Singh - thanks, that worked fine !