Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Android client: Basic connection - NullPointer Exception
Android client: Basic connection - NullPointer Exception [message #1396745] Tue, 08 July 2014 18:21 Go to next message
Allan Marube is currently offline Allan MarubeFriend
Messages: 2
Registered: July 2014
Junior Member
I created an MQTTAndroidClient. But when I call methods associated with the object like:
cleint.isConnected(); client.publish(); client.subscribe();
I get a NullPointerException. What could be the problem with my code. Here is a snippet:

try {
IMqttToken clientToken = clientOne.connect(connOpts,this, new StatusListener());
//clientOne.registerResources(this);

//clientToken.waitForCompletion();
System.out.println("connecting");

} catch (MqttException e) {
e.printStackTrace();
}

if (clientOne.isConnected()) {
Intent statusIntent = new Intent(this, ConnStatus.class);
startActivity(statusIntent);
}

I'd appreciate any help! Thanks!
Re: Android client: Basic connection - NullPointer Exception [message #1397175 is a reply to message #1396745] Wed, 09 July 2014 10:09 Go to previous messageGo to next message
Al Stockdill-Mander is currently offline Al Stockdill-ManderFriend
Messages: 1
Registered: July 2014
Junior Member
We should catch the the situation causing the NullPointer issue but the reason you're having this problem is that the client is asynchronous, so the call to connect returns immediately but it does not mean that you are connected so the call to isConnected() is happening before the client has completed connecting.
Re: Android client: Basic connection - NullPointer Exception [message #1397684 is a reply to message #1397175] Thu, 10 July 2014 03:02 Go to previous message
Allan Marube is currently offline Allan MarubeFriend
Messages: 2
Registered: July 2014
Junior Member
Yes. I figured that out as well. And I implemented the methods after the callback. Onsuccess(). But is this the best way to do this? Then why not using blocking client ?
Previous Topic:How to compile C++ libraries in Visual Studio
Next Topic:Android - Paho Mqtt client does not receive messages once network connectivity changes.
Goto Forum:
  


Current Time: Fri Apr 19 07:25:48 GMT 2024

Powered by FUDForum. Page generated in 0.02169 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top