Null Pointer Exception while using Vertx Async Client with MySQL

354 views
Skip to first unread message

Nikhil Khani

unread,
Mar 16, 2016, 11:46:01 PM3/16/16
to vert.x
We're trying to connect vertx with MySQL database and we're getting Null Pointer Exception (NPE) 


private static final String BE_4 = "localhost:3306";

private static final String DB_USER = "root";
private static final String DB_PWD = "root";

static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Exception while getting class");
e.printStackTrace();
}
}

private final JDBCClient client1 = JDBCClient.createShared(vertx,
new JsonObject().put("url", "jdbc:mysql://" + BE_0 + "/tweetdb").put("driver_class", "com.mysql.jdbc.Driver")
.put("max_pool_size", 100).put("user", DB_USER).put("password", DB_PWD));


And here's the stack trace:

java.lang.NullPointerException
        at java.util.Objects.requireNonNull(Objects.java:203)
        at io.vertx.ext.jdbc.impl.JDBCClientImpl.<init>(JDBCClientImpl.java:66)
        at io.vertx.ext.jdbc.JDBCClient.createShared(JDBCClient.java:82)
        at ServerManager.<init>(ServerManager.java:39)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at java.lang.Class.newInstance(Class.java:442)
        at io.vertx.core.impl.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:44)
        at io.vertx.core.impl.DeploymentManager.createVerticles(DeploymentManager.java:186)
        at io.vertx.core.impl.DeploymentManager.lambda$doDeployVerticle$157(DeploymentManager.java:159)
        at io.vertx.core.impl.DeploymentManager$$Lambda$7/1654589030.handle(Unknown Source)
        at io.vertx.core.impl.FutureImpl.checkCallHandler(FutureImpl.java:158)
        at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:100)
        at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:132)
        at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:104)
        at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:92)
        at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:546)
        at io.vertx.core.Starter.runVerticle(Starter.java:333)
        at io.vertx.core.Starter.run(Starter.java:130)
        at io.vertx.core.Starter.main(Starter.java:101)


We read in another thread that in the pom the version for core and async jdbc client should be same so we corrected it. 
Current pom:

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>3.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>

This is urgent.Could you assist us on this?

Thanks!


Paulo Lopes

unread,
Mar 17, 2016, 4:29:34 AM3/17/16
to vert.x
Reply all
Reply to author
Forward
0 new messages