I am using Smack 4.3.0 in Android Studio 3.2.1 and intend to try different functions in Smack. I have started to simply connect to my XMPP server which is running and I can connect to it using any other XMPP client. I use the following code to connect to the server before calling “login()” function:
Can anyone let me know why I get this error and why essentially the library should crash instead of throwing en exception?
Another question is that all documents in the repository are dated 2002-2008 and seem to be very outdated. Are these documents still valid? If yes, so why the date is misleading? If no, would you please let me know where can I find the latest document?
android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:276)
at libcore.io.IoBridge.sendto(IoBridge.java:509)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
at java.net.DatagramSocket.send(DatagramSocket.java:305)
at org.minidns.source.NetworkDataSource.queryUdp(NetworkDataSource.java:89)
at org.minidns.source.NetworkDataSource.query(NetworkDataSource.java:56)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:249)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:364)
at org.minidns.DnsClient.query(DnsClient.java:155)
at org.minidns.iterative.ReliableDnsClient.query(ReliableDnsClient.java:96)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:187)
at org.minidns.hla.ResolverApi.resolve(ResolverApi.java:113)
at org.minidns.hla.ResolverApi.resolve(ResolverApi.java:109)
at org.minidns.hla.ResolverApi.resolveSrv(ResolverApi.java:184)
at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.lookupSRVRecords0(MiniDnsResolver.java:74)
at org.jivesoftware.smack.util.dns.DNSResolver.lookupSRVRecords(DNSResolver.java:53)
at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:155)
at org.jivesoftware.smack.util.DNSUtil.resolveXMPPServiceDomain(DNSUtil.java:115)
at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMPPConnection.java:650)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:559)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:895)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:409)
It doesn’t give me any hint. The only thing I am suspecting is the IP number that I use as server domain since apparently the DNS lookup fails but this is how my test platform is setup. I appreciate if anyone can help.
The program crashes exactly when “connection.connect()” is executed.
IMHO the library should not crash in any circumstances even with invalid parameters as input. I assume that it is actually Smack that crashed as the log shows that DNS lookup inside the library fails.
What you show is a method call throwing an Exception. The first thing you should do when a method throws on you is to understand why it does that. Android’s NetworkOnMainThreadException is pretty well documented, I suggest you read up on it.
Hi,
Yes you are right! Thanks a lot for your hint. I used another thread to run the code and now it works. However, I still have problem with the certificates but I will ask in a separate thread.
Thanks again,
Dan