java操作Hbase数据库,在连接时报空指针异常makeZKProps

时间:2021-08-16 12:45:34
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NullPointerException
at org.apache.hadoop.hbase.zookeeper.ZKConfig.makeZKProps(ZKConfig.java:60)
at org.apache.hadoop.hbase.zookeeper.ZKConfig.getZKQuorumServersString(ZKConfig.java:245)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:147)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:127)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:1366)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.ensureZookeeperTrackers(HConnectionManager.java:611)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:871)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:846)
at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:271)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:211)
at org.apache.hadoop.hbase.client.HTableFactory.createHTableInterface(HTableFactory.java:36)
at org.apache.hadoop.hbase.client.HTablePool.createHTable(HTablePool.java:265)
at org.apache.hadoop.hbase.client.HTablePool.findOrCreateTable(HTablePool.java:195)
at org.apache.hadoop.hbase.client.HTablePool.getTable(HTablePool.java:174)
at com.yf.test.hbase.HBaseTablePool.getTable(HBaseTablePool.java:69)
at com.yf.test.hbase.HbaseTest.main(HbaseTest.java:43)

12 个解决方案

#1


最好能把代码贴出来

#2


是不是zookeeper目录配置的不对。

#3


log4j的:WARN没有追加程序能够找到记录仪(org.apache.hadoop.metrics2.lib.MutableMetricsFactory)。
log4j的:WARN请正确初始化log4j的系统。
log4j的:WARN见http://logging.apache.org/log4j/1.2/faq.html#noconfig更多信息。
在线程异常“主要”显示java.lang.NullPointerException

#4


package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#5


package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#6


引用 1 楼 zhangyufeng115 的回复:
最好能把代码贴出来
package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#7


配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

#8


该回复于2015-07-30 10:48:08被管理员删除

#9


引用 7 楼 zhangyufeng115 的回复:
配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");


加那个也没有用,反编译了下hbase的jar,发现是下面这块报的空指针
 ClassLoader cl = HQuorumPeer.class.getClassLoader();
    InputStream inputStream = cl.getResourceAsStream("zoo.cfg");//报错

#10


引用 7 楼 zhangyufeng115 的回复:
配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

解决了。

#11


引用 10 楼 yf275908654 的回复:
Quote: 引用 7 楼 zhangyufeng115 的回复:

配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

解决了。

结贴吧

#12


怎么弄的,我也有这个问题

#1


最好能把代码贴出来

#2


是不是zookeeper目录配置的不对。

#3


log4j的:WARN没有追加程序能够找到记录仪(org.apache.hadoop.metrics2.lib.MutableMetricsFactory)。
log4j的:WARN请正确初始化log4j的系统。
log4j的:WARN见http://logging.apache.org/log4j/1.2/faq.html#noconfig更多信息。
在线程异常“主要”显示java.lang.NullPointerException

#4


package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#5


package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#6


引用 1 楼 zhangyufeng115 的回复:
最好能把代码贴出来
package com.yf.test.hbase;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

public class HbaseTest {
//璁惧Hbase閾炬帴鍙傛暟
public static final Configuration configuration;  
    static {  
     Configuration config=new Configuration();
     config.addResource("hbase-site.xml");
     config.set("hbase.zookeeper.quorum", "ngix1");
     config.set("hbase.zookeeper.property.clientPort", "2181");
        configuration = HBaseConfiguration.create(config);
        
    } 
    
    public static void main(String args[]){
     createTable("test");
     //HBaseTablePool.getTable("last_metric");
    }
    
    public static void createTable(String tableName){
     System.out.println("Begin to create table...");
     try {
     HConnection connection = HConnectionManager.createConnection(configuration);
HBaseAdmin hBaseAdmin = new HBaseAdmin(connection);
if(hBaseAdmin.tableExists(tableName)){
hBaseAdmin.disableTable(tableName);
hBaseAdmin.deleteTable(tableName);
System.out.println("Table is existed...");
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("column01"));
desc.addFamily(new HColumnDescriptor("column02"));
desc.addFamily(new HColumnDescriptor("column03"));
hBaseAdmin.createTable(desc);
} catch (MasterNotRunningException e) {
System.out.println("HBase Master is not running...");
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
System.out.println("HBase Zookeeper is not running...");
e.printStackTrace();
}
     catch (IOException e) {
e.printStackTrace();
}
     System.out.println("end create table ......");  
    }
    
}

#7


配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

#8


该回复于2015-07-30 10:48:08被管理员删除

#9


引用 7 楼 zhangyufeng115 的回复:
配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");


加那个也没有用,反编译了下hbase的jar,发现是下面这块报的空指针
 ClassLoader cl = HQuorumPeer.class.getClassLoader();
    InputStream inputStream = cl.getResourceAsStream("zoo.cfg");//报错

#10


引用 7 楼 zhangyufeng115 的回复:
配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

解决了。

#11


引用 10 楼 yf275908654 的回复:
Quote: 引用 7 楼 zhangyufeng115 的回复:

配置一下hbase Master试试
configuration.set("hbase.master", "IP:60000");

解决了。

结贴吧

#12


怎么弄的,我也有这个问题