显示警告并且无法获得名册
Posted
技术标签:
【中文标题】显示警告并且无法获得名册【英文标题】:Showing Warning and Can't get Roster 【发布时间】:2014-08-06 07:29:42 【问题描述】:我使用过 asmack-android-17-0.8.3.jar 并使用以下代码。
private void testLogin()
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222,"Smack");
config.setSASLAuthenticationEnabled(true);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
config.setTruststoreType("AndroidCAStore");
config.setTruststorePassword(null);
config.setTruststorePath(null);
else
config.setTruststoreType("BKS");
String path = System.getProperty("javax.net.ssl.trustStore");
if (path == null)
path = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
config.setTruststorePath(path);
XMPPConnection xmpp = new XMPPConnection(config);
SASLAuthentication.registerSASLMechanism("X-FACEBOOK-PLATFORM",SASLXFacebookPlatformMechanism.class);
SASLAuthentication.supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
Log.i("XMPPClient",
"Access token to " + mFacebook.getAccessToken());
Log.i("XMPPClient",
"Access token to " + mFacebook.getAppId());
Log.i("XMPPClient",
"Access token to " + mFacebook.getAccessToken());
try
xmpp.connect();
Log.i("XMPPClient",
"Connected to " + xmpp.getHost());
catch (XMPPException e1)
Log.i("XMPPClient",
"Unable to " + xmpp.getHost());
e1.printStackTrace();
try
xmpp.login(APP_ID, mFacebook.getAccessToken());
Log.i("XMPPClient",
" its logined ");
//get roster
Roster roster = xmpp.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
System.out.println("Connected!");
System.out.println("\n\n" + entries.size() + " buddy(ies):");
for (RosterEntry entry : entries)
Log.i("test", entry.getName());
Log.i("test", entry.getUser());
//send a chat message
ChatManager chatmanager = xmpp.getChatManager();
Chat newChat = chatmanager.createChat("koko.mgmg@chat.facebook.com", new MessageListener()
@Override
public void processMessage(Chat chat, Message message)
// TODO Auto-generated method stub
Log.d("test", "message sent = "+ message);
);
newChat.sendMessage("Cowdy!");
catch (XMPPException e)
e.printStackTrace();
已经完成登录,但下面有警告显示,我无法获取名单和聊天。我认为以下警告会导致无法获得名册。如何解决这个问题以及如何获得名册和聊天?请。
08-06 03:12:52.719: W/System.err(2573): java.lang.NullPointerException
08-06 03:12:52.759: W/System.err(2573): at java.io.File.fixSlashes(File.java:185)
08-06 03:12:52.759: W/System.err(2573): at java.io.File.<init>(File.java:134)
08-06 03:12:52.759: W/System.err(2573): at java.io.FileInputStream.<init>(FileInputStream.java:105)
08-06 03:12:52.779: W/System.err(2573): at org.jivesoftware.smack.ServerTrustManager.<init>(ServerTrustManager.java:71)
08-06 03:12:52.779: W/System.err(2573): at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:871)
08-06 03:12:52.789: W/System.err(2573): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:221)
08-06 03:12:52.789: W/System.err(2573): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
08-06 03:12:52.789: W/System.err(2573): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
【问题讨论】:
【参考方案1】:试试这个,也许它对你有用,我有同样的问题,在我的情况下,以下解决方案工作正常。
从您的代码中注释以下代码,然后重试,
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
config.setTruststoreType("AndroidCAStore");
config.setTruststorePassword(null);
config.setTruststorePath(null);
else
config.setTruststoreType("BKS");
String path = System.getProperty("javax.net.ssl.trustStore");
if (path == null)
path = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
config.setTruststorePath(path);
【讨论】:
以上是关于显示警告并且无法获得名册的主要内容,如果未能解决你的问题,请参考以下文章