我試圖設置一個Android的Facebook聊天應用程序。 我已經使用XMPP許可實施了Facebook登錄。與XMPP的Android聊天應用程序
現在,如果我想只是測試我asmack.jar的基本連接設置我得到這個錯誤
12-18 21:29:48.845: E/AndroidRuntime(5516): FATAL EXCEPTION: main
12-18 21:29:48.845: E/AndroidRuntime(5516): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration
12-18 21:29:48.845: E/AndroidRuntime(5516): at com.example.messenger.MainActivity.testXMPP(MainActivity.java:68)
這裏是我的代碼。 我希望有人能幫忙。 (誤差在TestXMPP引起)
package com.example.messenger;
import java.util.Arrays;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.Session.StatusCallback;
import com.facebook.widget.LoginButton;
public class MainActivity extends FragmentActivity {
TextView TV1,TV2;
Button B1,B2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TV1 = (TextView) findViewById(R.id.textView1);
TV2 = (TextView) findViewById(R.id.textView2);
B1 = (Button) findViewById(R.id.button1);
B2 = (Button) findViewById(R.id.button2);
LoginButton authButton = (LoginButton) findViewById(R.id.authButton);
authButton.setReadPermissions(Arrays.asList("read_friendlists","xmpp_login"));
StatusCallback btn_callback = authButton.getSessionStatusCallback();
B1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String text3= "asdfasf";
Session act_session = Session.getActiveSession();
text3 = act_session.getPermissions().get(0)+act_session.getPermissions().get(1);
TV1.setText(text3);
}
});
B2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
testXMPP();
} catch (Exception e) {
// TODO Auto-generated catch block
TV2.setText(e.toString());
}
}
});
}
public void testXMPP()throws XMPPException{
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
config.setSASLAuthenticationEnabled(true);
config.setSecurityMode(SecurityMode.required);
config.setRosterLoadedAtLogin(true);
config.setTruststorePath("/system/etc/security/cacerts.bks");
config.setTruststorePassword("changeit");
config.setTruststoreType("bks");
//XMPPConnection xmpp = new XMPPConnection(config);
}
private static final String TAG = "MainFragment";
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession()
.onActivityResult(this, requestCode, resultCode, data);
}
}
當您添加將org.jivesoftware.smack.ConnectionConfiguration添加到您的應用程序的庫時,出現問題。檢查你的'/ libs'文件夾。 – zapl