AnsweredAssumed Answered

Smack-4.1.0-rc2 on Android

Question asked by jter on Mar 4, 2015
Latest reply on Mar 5, 2015 by jter

     Hello everyone!

     Recently, I am getting a demo on Android using smack-4.1.0-rc2 jars.

     when the demo run, it collapsed. The information was:

          java.lang.ExceptionInInitializerError

          at the line of "XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();"

     I appreciate your attention, Thanks !

Hear is activity_main.xml

    <Button

        android:id="@+id/sayhi"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="Say Hi To User2"

        android:textSize="10sp"/>

Here is MainActivity.java:

public class MainActivity extends Activity {

    private String ChatServer = "pc-20140623wbxi";

    private Button btn;

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

 

        btn = (Button) findViewById(R.id.sayhi);

        btn.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                new Thread() {

                    public void run() {

                        XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();  /** the error point**/

                        builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

                        builder.setUsernameAndPassword("user1@" + ChatServer, "000");

                        builder.setServiceName(ChatServer);

                        builder.setHost(ChatServer);

                        builder.setDebuggerEnabled(true);

 

                        AbstractXMPPConnection connection = new XMPPTCPConnection(builder.build());

 

                        connection.connect();

                        connection.login();

 

                        ChatManager chatManager = ChatManager.getInstanceFor(connection);

                        Chat newChat = chatManager.createChat("user2@" + ChatServer, new ChatMessageListener() {

                            @Override

                            public void processMessage(Chat chat, Message message) {

                                    chat.sendMessage(message);

                            }

                        });

 

                        newChat.sendMessage("I am User1 !!!");

                  

                        chatManager.addChatListener(new ChatManagerListener() {

                            @Override

                            public void chatCreated(Chat chat, boolean b) {

                                chat.addMessageListener(new ChatMessageListener() {

                                    @Override

                                    public void processMessage(Chat chat, Message message) {

                                    }

                                });

                            }

                        });

                    }

                }.start();

            }

        });

    }

}

Outcomes