为什么我的 android 应用在连接到 mqtt 代理时给出 "your app keeps stopping"

Why my android app is giving "your app keeps stopping" while connecting to mqtt broker

我编写了一个代码,将我的 android 应用程序连接到 android studio 中的 mqtt 服务器。我添加了按钮 "connect",点击后它会在屏幕上显示连接消息。当我点击连接按钮时,我收到消息说你的 android 应用一直在停止。这是我的代码。我已经上传了必要的存储库和依赖项以及权限

public class MainActivity extends AppCompatActivity {
    MqttAndroidClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String clientId = MqttClient.generateClientId();
        client =
                new MqttAndroidClient(this.getApplicationContext(), "tcp://mqtt.eclipse.org:1883",
                        clientId);


    }

    public void test(View V){
        try {
            IMqttToken token = client.connect();
            token.setActionCallback(new IMqttActionListener() {
                @Override
                public void onSuccess(IMqttToken asyncActionToken) {
                    // We are connected
                    Toast.makeText(MainActivity.this,"connected",Toast.LENGTH_LONG).show();

                }

                @Override
                public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
                    Toast.makeText(MainActivity.this,"disconnected",Toast.LENGTH_LONG).show();
                }
            });
        } catch (MqttException e) {
            e.printStackTrace();
        }
    }
}

错误已解决。本地广播管理器文件有问题。