Cobalt: NullPointerException - Cannot evaluate WhatsappWebSocket.toString()

This is the code

    public static void main(String[] args) {
        var api = new WhatsappAPI();
        api.registerListener(new MyListener(api));
        api.connect();
    }
public class MyListener implements WhatsappListener {
    private final WhatsappAPI api;
    public MyListener(WhatsappAPI api){
        this.api = api;
    }

    public void onLoggedIn(@NonNull UserInformationResponse info) {
        System.out.println("Connected :)");
    }

    public void onChats(){
        System.out.printf("Recived chats: %s%n", api.manager().chats());
    }
}

And this is the error message:

issue

Any ideas what I’m doing wrong?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

looks good: now I see a large QR code all over the screen. Offtopic: Is it possible for the code to be displayed a little smaller?

use this code to print the qr to ur path

BufferedImage image = MatrixToImageWriter.toBufferedImage(qr); File outputfile = new File("image.jpg"); ImageIO.write(image, "jpg", outputfile);

OK thanks. Is that also the explanation why I am not getting a connection?

I think I have the same error, it just never connects, it doesn’t work @Auties00

I try to connect but I never receive a qr code, the code is similar to the example and no errors are displayed.

I had that. This is my listener (from your documentation):

public class MyListener implements WhatsappListener {
    private final WhatsappAPI api;
    public MyListener(WhatsappAPI api){
        this.api = api;
    }

    public void onLoggedIn(@NonNull UserInformationResponse info) {
        System.out.println("Connected :)");
    }

    public void onChats(){
        System.out.printf("Recived chats: %s%n", api.manager().chats());
    }
}

Should be fixed in 2.2.2. Can you please double check?