Android/Eclipse Error - “Could not find class 'org.jivesoftware.smack.ConnectionConfiguration', referenced from method”

半世苍凉 提交于 2020-01-30 03:27:06

问题


This is my first time working with Android/Java. I am trying to run this basic code and I keep getting the following error:

"Could not find class 'org.jivesoftware.smack.ConnectionConfiguration', referenced from method"

  • My code:

    package message.pack;
    import org.jivesoftware.smack.ConnectionConfiguration;
    import org.jivesoftware.smack.XMPPConnection;
    import org.jivesoftware.smack.XMPPException;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class ThesimpleigniteandroidActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
        }
    
                  public static void main(String[] args) {
                  ConnectionConfiguration conf = new     ConnectionConfiguration("jabber.com",5222);
                  XMPPConnection connection = new XMPPConnection(conf);
                      try {
                      connection.connect();
                      connection.login("myusername", "mypassword");
                      } catch (XMPPException e) {
                      e.printStackTrace();
                      } finally {
                              connection.disconnect();
                      }
                      }
                      }
    

I am using the smack.jar from this page:

http://vidorsolutions.blogspot.com/2011/01/writing-xmppjabber-chat-application-for.html?m=1

Can anyone tell me what I am doing wrong?


回答1:


This is similar to many related problems surrounding External jars in android projects (especially with the new sdk tools). The solution is for you to create a folder in your project called libs and copy the jars into that folder.




回答2:


Did you put the jar file in your eclipse path?

This will tell you how to do so: http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)



来源:https://stackoverflow.com/questions/11002762/android-eclipse-error-could-not-find-class-org-jivesoftware-smack-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!