Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Help! Paho MQTT Android Application

Hi Golnaz,

as you can see, the exception is related to the "default file persistence", which is used to store the client state on disk or other file system, so it can be retrieved if the client is recreated.

The default location for the file system persistence (. I think) is probably not writeable on your Android system.  Two solutions, if this is the case:

1) turn off the file persistence completely, by creating the client like so:

client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2", null);

2) set the file persistence to a writeable directory:

MqttDefaultFilePersistence fp = MqttDefaultFilePersistence("writeable directory name");
client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2", fp);


On 05/02/14 13:23, Golnaz Makhtoumi wrote:

Hi All,


I want to stablish a connection to local broker (Mosquitto) by MQTT.

The simple java project is working and I can publish a message.


But now when I want to use the same concept in Android project, it only goes to exception.

Here is the main code inside the (which is a service)



            public void onCreate() {

                         // TODO Auto-generated method stub


            Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

                         try {

                               client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2");


                               MqttMessage message = new MqttMessage();

                               message.setPayload("A single wessage".getBytes());

                               client.publish("pahodemo/test", message);


                             } catch (MqttException e) {

                               Toast.makeText(this, "went to exception", Toast.LENGTH_LONG).show();






It seems like it does go into try but cannot create instance of MqttClient and then throws exception.


In logcat under syste,.err tag I get MqttException(0) at

And so on..


What am I doing wrong?


Thanks in advance


paho-dev mailing list

Back to the top