Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:06:48+00:00 2026-06-14T18:06:48+00:00

I’m trying to create an MqttClient in Android, using an Android emulator (Nexus7) on

  • 0

I’m trying to create an MqttClient in Android, using an Android emulator (Nexus7) on ADT (Eclipse 3.8.0 on a Linux Fedora17.
I found this question answered (Android MQTT unable to create client), but it failed to solve my problem.

I created an activity that allows the user to enter the directory where to store the presistence file, but there is no way to avoid catching the exception.
I tried with “/mnt/sdcard/”, “/mnt/”, “/mnt/sdcard/tmp/” and similar.

Do I need to pay attention to particular settings in Android emulator on in Eclipse project?
Are there any uses-permissions to be included in the application?

I looked at the various mqtt resources mentioned in the quoted answered question, but I couldn’t manage to find an answer.

This is my code:

package com.storassa.android.mqttsample;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;

public class MqttSample extends Activity {

    Button okButton = null;
    AutoCompleteTextView inputTextView = null;
    TextView errorTextView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mqtt_sample);

        okButton = (Button)findViewById(R.id.okButton);
        inputTextView = (AutoCompleteTextView)findViewById(R.id.InputText);
        errorTextView = (TextView)findViewById(R.id.errorText);

        okButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                try {
                    String dir = inputTextView.getText().toString();
                    MqttDefaultFilePersistence mdfp = new MqttDefaultFilePersistence(
                            dir);
                    MqttClient client = new MqttClient("tcp://127.0.0.1:1833",
                            "0001", mdfp);
                }
                catch (Exception e) {
                    String errorText = "";
                    for (StackTraceElement error : e.getStackTrace())
                        errorText += error.toString() + "\n";
                    errorTextView.setText(errorText);
                }
            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_mqtt_sample, menu);
        return true;
    }

}

and this is the Stack:

MqttException(0) at
org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:74)
org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:183)
com.storassa.android.mqttsample.MqttSample$1.onClick(MqttSample.java:38)
android.view.View.performClick(View.java:4202)
android.view.View$PerformClick.run(View.java:17340)
android.os.Handler.handleCallback(Handler.java:725)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5039)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
dalvik.system.NativeStart.main(Native Method)    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:06:49+00:00Added an answer on June 14, 2026 at 6:06 pm

    After a whole day spent in understanding the issue and in googling anywhere to find it, eventually I got it: very simply a permission has to be added to the manifest

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    

    I don’t know whether internal directories can be used instead of the sdcard.

    As this is the first time I answer my own question, let me know whether it is a good etiquette to flag as correct answer my own answer (I found different opinions on this topics)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.