2 ty793187547 ty793187547 于 2015.06.16 22:23 提问

android openfire 注册时报错

IQ.Type.ERROR: internal-server-error(500)

public void register(String account, String password) {

if (XmppConnectionManager.connection == null)
Toast.makeText(AddFriendActivity.this, "服务器无响应~", Toast.LENGTH_SHORT).show();
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(XmppConnectionManager.connection.getServiceName());
reg.setUsername(account);// 注意这里createAccount注册时,参数是username,不是jid,是“@”前面的部分。
reg.setPassword(password);
reg.addAttribute("android", "geolo_createUser_android");// 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = XmppConnectionManager.connection.createPacketCollector(filter);
XmppConnectionManager.connection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();// 停止请求results(是否成功的结果)
if (result == null) {
Log.e("RegistActivity", "No response from server.");
Toast.makeText(AddFriendActivity.this, "服务器无响应~", Toast.LENGTH_SHORT).show();
} else if (result.getType() == IQ.Type.RESULT) {
Toast.makeText(AddFriendActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("RegistActivity", "IQ.Type.ERROR: "+ result.getError().toString());
Toast.makeText(AddFriendActivity.this, "这个账号已经存在", Toast.LENGTH_SHORT).show();
} else {
Log.e("RegistActivity", "IQ.Type.ERROR: "+ result.getError().toString());
Toast.makeText(AddFriendActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
}
}
}

1个回答

devmiao
devmiao   Ds   Rxr 2015.06.16 22:44

加上一个try catch看看输出什么错误呢

Csdn user default icon
上传中...
上传图片
插入图片