Я пытаюсь подключиться к своему MqttServer, но не могу заставить его работать ...
Возможно, это простая вещь, но я не могу ее найти.
MainActivity . java выглядит так:
private Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String clientId = MqttClient.generateClientId();
final MqttAndroidClient client =
new MqttAndroidClient(MainActivity.this, "tcp://mymqttserver.com:port",
clientId);
try {
MqttConnectOptions options = new MqttConnectOptions();
options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1);
options.setUserName("xxxx");
options.setPassword("yyyy".toCharArray());
IMqttToken token = client.connect(options);
token.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
// We are connected
Toast.makeText(MainActivity.this, "connected", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
// Something went wrong e.g. connection timeout or firewall problems
Toast.makeText(MainActivity.this, "not connected", Toast.LENGTH_SHORT).show();
}
});
} catch (MqttException e) {
e.printStackTrace();
}
}
});
}
}
logcat:
2020-01-30 20:33:30.766 5109-5109/? I/art: Not late-enabling -Xcheck:jni (already on)
2020-01-30 20:33:30.766 5109-5109/? W/art: Unexpected CPU variant for X86 using defaults: x86
2020-01-30 20:33:30.874 5109-5109/firstlook.gohool.mqttconnect W/System: ClassLoader referenced unknown path: /data/app/firstlook.gohool.mqttconnect-2/lib/x86
2020-01-30 20:33:30.916 5109-5109/firstlook.gohool.mqttconnect W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2559)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:63)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:787)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:749)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:659)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:552)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:161)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void firstlook.gohool.mqttconnect.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:25)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6679)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2618)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.os.Looper.loop() (Looper.java:154)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
2020-01-30 20:33:30.926 5109-5109/firstlook.gohool.mqttconnect I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/firstlook.gohool.mqttconnect-2/base.apk"],nativeLibraryDirectories=[/data/app/firstlook.gohool.mqttconnect-2/lib/x86, /system/lib, /vendor/lib]]
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2559)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:63)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:787)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:749)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:659)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:552)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:161)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void firstlook.gohool.mqttconnect.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:25)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6679)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2618)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2726)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1477)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.os.Looper.loop() (Looper.java:154)
2020-01-30 20:33:30.927 5109-5109/firstlook.gohool.mqttconnect I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
2020-01-30 20:33:30.928 5109-5109/firstlook.gohool.mqttconnect I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2020-01-30 20:33:30.928 5109-5109/firstlook.gohool.mqttconnect I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
2020-01-30 20:33:30.928 5109-5109/firstlook.gohool.mqttconnect I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)
2020-01-30 20:33:31.060 5109-5127/firstlook.gohool.mqttconnect I/OpenGLRenderer: Initialized EGL, version 1.4
2020-01-30 20:33:31.060 5109-5127/firstlook.gohool.mqttconnect D/OpenGLRenderer: Swap behavior 1
2020-01-30 20:33:31.061 5109-5127/firstlook.gohool.mqttconnect W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-01-30 20:33:31.061 5109-5127/firstlook.gohool.mqttconnect D/OpenGLRenderer: Swap behavior 0
2020-01-30 20:33:31.071 5109-5127/firstlook.gohool.mqttconnect D/EGL_emulation: eglCreateContext: 0xa86051e0: maj 3 min 0 rcv 3
2020-01-30 20:33:31.094 5109-5109/firstlook.gohool.mqttconnect I/ViewConfigCompat: Could not find method getScaledScrollFactor() on ViewConfiguration
2020-01-30 20:33:31.113 5109-5127/firstlook.gohool.mqttconnect D/EGL_emulation: eglMakeCurrent: 0xa86051e0: ver 3 0 (tinfo 0xa8603230)
2020-01-30 20:33:31.115 5109-5127/firstlook.gohool.mqttconnect E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
2020-01-30 20:33:31.115 5109-5127/firstlook.gohool.mqttconnect E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
2020-01-30 20:33:31.124 5109-5127/firstlook.gohool.mqttconnect D/EGL_emulation: eglMakeCurrent: 0xa86051e0: ver 3 0 (tinfo 0xa8603230)
2020-01-30 20:33:33.513 5109-5109/firstlook.gohool.mqttconnect D/AndroidRuntime: Shutting down VM
2020-01-30 20:33:33.513 5109-5109/firstlook.gohool.mqttconnect E/AndroidRuntime: FATAL EXCEPTION: main
Process: firstlook.gohool.mqttconnect, PID: 5109
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/localbroadcastmanager/content/LocalBroadcastManager;
at org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:445)
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:423)
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:330)
at firstlook.gohool.mqttconnect.MainActivity$1.onClick(MainActivity.java:41)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.localbroadcastmanager.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/firstlook.gohool.mqttconnect-2/base.apk"],nativeLibraryDirectories=[/data/app/firstlook.gohool.mqttconnect-2/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:445)
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:423)
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:330)
at firstlook.gohool.mqttconnect.MainActivity$1.onClick(MainActivity.java:41)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Вот и все, у меня были проблемы с запуском простого приложения с этим кодом но я это как-то исправил. Так что это даст мне еще одну проблему, и я не знаю, как ее решить.