Note that there are some explanatory texts on larger screens.

plurals
  1. POaSmack crashes with NetworkOnMainThreadException
    primarykey
    data
    text
    <p>I apologize for the formatting in advance. I am new-ish to android development and I am working on an XMPP Client to talk to a server at the house to do commands via Google talk bots....</p> <ol> <li>I did look at stackoverflow for some answers and googled some answers</li> <li>I updated to latest ASMACK lib via github</li> <li>I did add the uses permission</li> <li>I got ASMACK to work on a test app on my android.</li> </ol> <p>I copied the working code to my application I am trying to make and gives me errors... like I said I am new and haven't done java programming in 10 years.. i don't know how to heard the error stack</p> <p>I have a dialog with settings called 'Setting Dialog'. when I click the button I run this:</p> <p><code> </p> <pre><code> protected void onStart() { super.onStart(); setContentView(R.layout.settings); getWindow().setFlags(4, 4); setTitle("XMPP Settings"); Button ok = (Button) findViewById(R.id.ok); ok.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String host = HOST_ADDRESS; int port = HOST_PORT_NUM; String service = HOST_SERVICE; String username = "me@gmail.com";//getText(R.id.userid); String password = "abc123";//getText(R.id.password); // Create a connection ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); XMPPConnection XMPPCon = new XMPPConnection(connConfig); try { XMPPCon.connect(); XMPPCon.login(username,password); } catch (XMPPException ex) { ex.printStackTrace(); HomeBotClient.setConnection(null); } HomeBotClient.setConnection(XMPPCon); dismiss(); } } ); } </code></pre> <p></code></p> <p>That calls this a function "setConnection" in the main activity</p> <p><code> public void setConnection (XMPPConnection XMPPCon) {</p> <pre><code> this.XMPPCon = XMPPCon; if (XMPPCon != null) { ChatManager chatmanager = XMPPCon.getChatManager(); Chat newChat = chatmanager.createChat("psun03@gmail.com",new MessageListener() { public void processMessage(Chat chat, Message message) { try { Log.v(TAG, "Got:" + message.getBody()); chat.sendMessage(message.getBody()); } catch (XMPPException e) { e.printStackTrace(); Log.v(TAG, "Couldn't respond:" + e); } Log.v(TAG, message.toString()); } }); try { newChat.sendMessage("OMNOMNOM"); } catch (XMPPException e) { e.printStackTrace(); Log.v(TAG, "couldn't send:" + e.toString()); } // Accept only messages from friend@gmail.com PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter("psun03@gmail.com")); // Collect these messages PacketCollector collector = XMPPCon.createPacketCollector(filter); while(true) { Packet packet = collector.nextResult(); if (packet instanceof Message) { Message msg = (Message) packet; // Process message Log.v(TAG, "Got message:" + msg.getBody()); } } } } </code></pre> <p></code></p> <p>I get this error when I push the button</p> <p><code> 04-07 17:21:15.011: E/AndroidRuntime(1099): FATAL EXCEPTION: main 04-07 17:21:15.011: E/AndroidRuntime(1099): android.os.NetworkOnMainThreadException 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117) 04-07 17:21:15.011: E/AndroidRuntime(1099): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 04-07 17:21:15.011: E/AndroidRuntime(1099): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 04-07 17:21:15.011: E/AndroidRuntime(1099): at java.net.InetAddress.getAllByName(InetAddress.java:214) 04-07 17:21:15.011: E/AndroidRuntime(1099): at org.jivesoftware.smack.proxy.DirectSocketFactory.createSocket(DirectSocketFactory.java:49) 04-07 17:21:15.011: E/AndroidRuntime(1099): at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:576) 04-07 17:21:15.011: E/AndroidRuntime(1099): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1034) 04-07 17:21:15.011: E/AndroidRuntime(1099): at com.ps.homebotclient.SettingsDialog$1.onClick(SettingsDialog.java:53) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.view.View.performClick(View.java:4204) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.view.View$PerformClick.run(View.java:17355) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.os.Handler.handleCallback(Handler.java:725) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.os.Handler.dispatchMessage(Handler.java:92) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.os.Looper.loop(Looper.java:137) 04-07 17:21:15.011: E/AndroidRuntime(1099): at android.app.ActivityThread.main(ActivityThread.java:5041) 04-07 17:21:15.011: E/AndroidRuntime(1099): at java.lang.reflect.Method.invokeNative(Native Method) 04-07 17:21:15.011: E/AndroidRuntime(1099): at java.lang.reflect.Method.invoke(Method.java:511) 04-07 17:21:15.011: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-07 17:21:15.011: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-07 17:21:15.011: E/AndroidRuntime(1099): at dalvik.system.NativeStart.main(Native Method)</p> <p></code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload