Exception in thread “main“ java.lang.NullPointerException at com.zs.zookeeper.DistributeServer.reg(代
Posted ZSYL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exception in thread “main“ java.lang.NullPointerException at com.zs.zookeeper.DistributeServer.reg(代相关的知识,希望对你有一定的参考价值。
问题描述
执行ZooKeeper-Java主程序代码时,发生空指针异常:
Exception in thread "main" java.lang.NullPointerException
at com.zs.zookeeper.DistributeServer.regist(DistributeServer.java:30)
at com.zs.zookeeper.DistributeServer.main(DistributeServer.java:16)
解决方案
原来是代码有误:
private ZooKeeper zkClient;
private void getConnect() throws IOException {
ZooKeeper zkClient = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
@Override
public void process(WatchedEvent watchedEvent) {
}
});
我在方法外面声明了全局变量zkClient,之后又再方法内声明重名的局部变量,导致全局变量未被初始化,因此空指针异常报错。
hadoop102 is online...
去除之后就行了!
加油!
感谢!
努力!
以上是关于Exception in thread “main“ java.lang.NullPointerException at com.zs.zookeeper.DistributeServer.reg(代的主要内容,如果未能解决你的问题,请参考以下文章
错误:Exception in thread “main“ java.lang.ClassCastException
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
Exception in thread "main" java.lang.NullPointerException at Class.main
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" org.springframework.mail.MailSendException; nested exception de
Exception in thread “main“ java.lang.NoClassDefFoundError: org/apache/flink/