我想在我的項目中做一個小工作。在eclipse中創建一個標準項目,將jar文件(smack.jar,smackx-debug.jar,smackx-jingle.jar,smackx.jar)添加到libs文件夾中。開始使用XMPP類,但我不確定是否還有其他事情我應該做,以便正確設置項目(稍後),因爲它不起作用。當我運行的應用程序,我正在此錯誤Could not find class 'java.beans.PropertyDescriptor', referenced from method org.jivesoftware.smack.util.PacketParserUtils.parseWithIntrospection
,當我嘗試發送短信我收到此錯誤java.lang.IllegalStateException: Not connected to server.
和at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:445)
帶有aSmack庫的XMPP出錯?
這是我使用
public class ClientJabberActivity extends Activity {
private final static String server_host = "aaaaa.com" ;
private final static int SERVER_PORT = 5222 ;
private final static String SERVICE_NAME = "gmail.com" ;
private final static String LOGIN = "[email protected]" ;
private final static String PASSWORD = "yyyy";
ArrayList<String> m_discussionThread;
ArrayAdapter<String> m_discussionThreadAdapter;
XMPPConnection m_connection;
private Handler m_handler;
@ Override
public void onCreate (Bundle savedInstanceState) {
super . onCreate (savedInstanceState);
setContentView (R.layout.main);
m_handler = new Handler();
try {
initConnection();
} catch (XMPPException e) {
e. printStackTrace();
}
final EditText recipient = (EditText) this . findViewById (R.id.recipient);
final EditText message = (EditText) this . findViewById (R.id.message);
ListView list = (ListView) this . findViewById (R.id.thread);
m_discussionThread = new ArrayList<String>();
m_discussionThreadAdapter = new ArrayAdapter<String> (this ,
R.layout.multi_line_list_item, m_discussionThread);
list.setAdapter(m_discussionThreadAdapter);
Button send = (Button) this . findViewById (R.id.send);
send. setOnClickListener (new View. OnClickListener() {
public void onClick (View view) {
String to = recipient.getText().toString();
String text = message.getText().toString();
Message msg = new Message(to, Message.Type.chat);
msg.setBody(text);
m_connection.sendPacket (msg);
m_discussionThread. add (" Me : ");
m_discussionThread. add (text);
m_discussionThreadAdapter. notifyDataSetChanged();
}
});
}
private void initConnection() throws XMPPException {
ConnectionConfiguration config = new ConnectionConfiguration (server_host, SERVER_PORT, SERVICE_NAME);
m_connection = new XMPPConnection (config);
m_connection.connect();
m_connection.login(LOGIN, PASSWORD);
Presence presence = new Presence(Presence.Type.available);
Log.i("ID", ""+presence);
m_connection.sendPacket (presence);
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
m_connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message.getFrom());
m_discussionThread.add(fromName + ":");
m_discussionThread.add(message.getBody());
m_handler.post(new Runnable() {
public void run() {
m_discussionThreadAdapter.notifyDataSetChanged();
}
});
}
}
}, filter);
ChatManager chatmanager = m_connection.getChatManager();
chatmanager.addChatListener(new ChatManagerListener()
{
public void chatCreated(final Chat chat, final boolean createdLocally)
{
chat.addMessageListener(new MessageListener()
{
public void processMessage(Chat chat, Message message)
{
System.out.println("Received message: "
+ (message != null ? message.getBody() : "NULL"));
Log.i("CHAT USER", "Received message is: "+message.getBody());
}
});
}
});
}
}
任何人的代碼都經歷了這個問題您的XMPP客戶端。是否在jar文件或任何我需要更改我的代碼中的任何東西的問題...
由於Steffen說你好像使用錯誤的罐子。使用這個jar http://code.google.com/p/gtalksms/source/browse/libs/asmack-android-5.jar它通常是最新的。 – Jug6ernaut
雅我在jar文件中做了一個錯誤,現在它的工作爲Gmail帳戶,但不是我的服務器帳戶會是什麼問題.... –
好。關於你的問題。你必須更清楚地解釋現在的問題。 –