Es kann keine neue Verbindung mit aSmack 4.0.2 hergestellt werden
Ich lerne Android-Programmierung und versuche das jetzt schon seit ein paar Tagen herauszufinden. Ich schreibe eine Android-App, die eine Verbindung zum XMPP-Server herstellen soll. Ich bekomme die ganze Zeit den gleichen Fehler und weiß nicht wirklich, was ich falsch mache. Ich habe mit Google gefundene Beispielcodes ausprobiert, kann aber auch keine Verbindung mit ihnen herstellen.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = getApplicationContext();
SmackAndroid.init(context);
ConnectionConfiguration ConnectionConfiguration = new ConnectionConfiguration("192.168.0.101", 5222);
ConnectionConfiguration.setDebuggerEnabled(true);
XMPPConnection connection = new XMPPTCPConnection(ConnectionConfiguration);
try {
connection.connect();
} catch (ConnectionException e) {
Log.e("ERROR", "ConnectionException", e);
for (int i = 0; i < e.getFailedAddresses().size(); i++) {
HostAddress element = e.getFailedAddresses().get(i);
Log.e("ERROR", element.getErrorMessage().toString());
}
} catch (Exception e) {
Log.e("ERROR", "Exception", e);
}
// Log into the server
try {
connection.login("user", "password", "SomeResource");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Dies ist ein Fehler, den ich erhalte:
08-11 15:48:27.476: E/ERROR(11117): ConnectionException
08-11 15:48:27.476: E/ERROR(11117): org.jivesoftware.smack.SmackException$ConnectionException
08-11 15:48:27.476: E/ERROR(11117): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:433)
08-11 15:48:27.476: E/ERROR(11117): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:808)
08-11 15:48:27.476: E/ERROR(11117): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
08-11 15:48:27.476: E/ERROR(11117): at com.example.gps_pubsub.MainActivity.onCreate(MainActivity.java:34)
08-11 15:48:27.476: E/ERROR(11117): at android.app.Activity.performCreate(Activity.java:5047)
08-11 15:48:27.476: E/ERROR(11117): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
08-11 15:48:27.476: E/ERROR(11117): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
08-11 15:48:27.476: E/ERROR(11117): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
08-11 15:48:27.476: E/ERROR(11117): at android.app.ActivityThread.access$700(ActivityThread.java:134)
08-11 15:48:27.476: E/ERROR(11117): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
08-11 15:48:27.476: E/ERROR(11117): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 15:48:27.476: E/ERROR(11117): at android.os.Looper.loop(Looper.java:137)
08-11 15:48:27.476: E/ERROR(11117): at android.app.ActivityThread.main(ActivityThread.java:4867)
08-11 15:48:27.476: E/ERROR(11117): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 15:48:27.476: E/ERROR(11117): at java.lang.reflect.Method.invoke(Method.java:511)
08-11 15:48:27.476: E/ERROR(11117): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
08-11 15:48:27.476: E/ERROR(11117): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
08-11 15:48:27.476: E/ERROR(11117): at dalvik.system.NativeStart.main(Native Method)
08-11 15:48:27.476: E/ERROR(11117): 192.168.0.101:5222 Exception: null
Ich habe auch überprüft, ob die Firewall Verbindungen zulässt, und versucht, eine Verbindung zum hosted.im-Dienst anstelle des Heimservers herzustellen, mit demselben Ergebnis.
I have this line added to MANIFEST:
<uses-permission android:name="android.permission.INTERNET"/>