Cobalt: Authentication fails from last connection

Hi @Auties00,

I’m using this piece of code to get a connection. When I removed all the serialized connections, I get a QR code and everything seems fine. But when I restart my application, it’s using the “lastConnection” and I got the error below.

Seems like something is off at serializing/deserializing the connections?

Whatsapp api;
if (Whatsapp.listConnections().isEmpty()) {
                var configuration = Whatsapp.Options.newOptions()
                        .description("MyApp")
                        .create();
                api = Whatsapp.newConnection(configuration);
            } else {
                api = Whatsapp.lastConnection();
            }
            api.connect().get();

Error

Caused by: java.lang.NullPointerException: Cannot invoke "it.auties.whatsapp.model.media.MediaConnection.auth()" because the return value of "it.auties.whatsapp.controller.Store.mediaConnection()" is null
	at it.auties.whatsapp.util.Medias.upload(Medias.java:51)
	at it.auties.whatsapp.model.message.standard.ImageMessage.simpleBuilder(ImageMessage.java:179)
	at it.auties.whatsapp.model.message.standard.ImageMessage$SimpleImageBuilder.create(ImageMessage.java:172)
	at be.geertdebaets.camera.service.WhatsAppService.sendImageMessageToGroup(WhatsAppService.java:147)
	... 1 more

Version: <version>3.0-RC13</version> (but was also on RC12)

Is this a bug/problem, or i’m a doing something wrong in setting up the connections?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 34 (14 by maintainers)

Most upvoted comments

Hi @Auties00,

I’m using this piece of code to get a connection. When I removed all the serialized connections, I get a QR code and everything seems fine. But when I restart my application, it’s using the “lastConnection” and I got the error below.

Seems like something is off at serializing/deserializing the connections?

Whatsapp api;
if (Whatsapp.listConnections().isEmpty()) {
                var configuration = Whatsapp.Options.newOptions()
                        .description("MyApp")
                        .create();
                api = Whatsapp.newConnection(configuration);
            } else {
                api = Whatsapp.lastConnection();
            }
            api.connect().get();

Error

Caused by: java.lang.NullPointerException: Cannot invoke "it.auties.whatsapp.model.media.MediaConnection.auth()" because the return value of "it.auties.whatsapp.controller.Store.mediaConnection()" is null
	at it.auties.whatsapp.util.Medias.upload(Medias.java:51)
	at it.auties.whatsapp.model.message.standard.ImageMessage.simpleBuilder(ImageMessage.java:179)
	at it.auties.whatsapp.model.message.standard.ImageMessage$SimpleImageBuilder.create(ImageMessage.java:172)
	at be.geertdebaets.camera.service.WhatsAppService.sendImageMessageToGroup(WhatsAppService.java:147)
	... 1 more

Version: <version>3.0-RC13</version> (but was also on RC12)

Is this a bug/problem, or i’m a doing something wrong in setting up the connections?

just fixed it, it will be available in the next update

I’m trying all types of connection examples but I can’t get a QR code. When I try to do “api.connect().get()” (my last test is with some code of @GDB4J), but code is freezing and make serialized connection, under “.whatsappweb4j” only after stop application. I’m on MacOs.

There is some solutions?

Hi @19Maury85 , I’ve struggled aslo with getting a QRCode at first.

The easiest way to start is running one of the examples and see if you can get a QRCode there. There you will see the easiest way to get a connection is this one (I believe):

var api = Whatsapp.lastConnection()
                .connect()
                .get();

It wil create a new connection if no connection was saved before. Check also your {user.home}/.whatsappweb4j folder and perhaps try to delete everything from there On windows C:/users/<your_username>/.whatsappweb4j On Linux /home/<your_username>/.whatsappweb4j

My problem ended up using a too recent dependency version of “jakarta.websocket-api” See issues (but this when working with Spring Boot) : https://github.com/Auties00/WhatsappWeb4j/issues/111 https://github.com/Auties00/WhatsappWeb4j/issues/105

Kind regards

I’m trying all types of connection examples but I can’t get a QR code. When I try to do “api.connect().get()” (my last test is with some code of @GDB4J), but code is freezing and make serialized connection, under “.whatsappweb4j” only after stop application. I’m on MacOs.

There is some solutions?