gpt4 book ai didi

调用 vcard.load(conn) 时 Android asmack vcard classcastException

转载 作者:行者123 更新时间:2023-11-29 20:59:01 26 4
gpt4 key购买 nike

我正在使用来自 http://asmack.freakempire.de/4.0.5/ 的 asmack-android-8-4.0.5.jar 我能够成功连接和登录,但是当我尝试加载我自己的 vcard 时,它会在 vcard.doload 方法中抛出 classcastexception。请帮助任何人。下面是我正在使用的完整代码。

private class ConnectTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {

Roster.setDefaultSubscriptionMode(SubscriptionMode.accept_all);
configure(new ProviderManager());
ConnectionConfiguration config = new ConnectionConfiguration(
"my host here", 5222, "xmpp.jp");
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setCompressionEnabled(true);
ProviderManager.addIQProvider("vCard", "vcard-temp",
new VCardProvider());
connection = new XMPPTCPConnection(config);
try {
connection.connect();
System.out.println("sanidhya09 connected");

try {
connection.login("sanidhya09", "*****");
System.out.println("sanidhya09 logged in ");
} catch (SaslException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

} catch (Exception e) {
System.err.println("sanidhya09 Failed to connect to "
+ "xmpp.jp");
return null;
}
return null;
}

protected void onPostExecute(Long result) {
Presence pres = new Presence(Presence.Type.available);

try {
connection.sendPacket(pres);
} catch (NotConnectedException e1) {
e1.printStackTrace();
}
VCard vCard = new VCard();
try {
ProviderManager.addIQProvider("vCard", "vcard-temp",
new VCardProvider());
System.out.println("sanidhya09 vcard trying");
vCard.load(connection);
System.out.println("sanidhya09 vcard loaded");

} catch (Exception e) {
e.printStackTrace();
}
}
}

这是异常(exception)情况:

  java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to org.jivesoftware.smackx.vcardtemp.packet.VCard
11-05 16:09:57.379: W/System.err(26675): at org.jivesoftware.smackx.vcardtemp.packet.VCard.doLoad(VCard.java:560)
11-05 16:09:57.379: W/System.err(26675): at org.jivesoftware.smackx.vcardtemp.packet.VCard.load(VCard.java:542)
11-05 16:09:57.379: W/System.err(26675): at com.sanidhya.chatdemo.MainActivity$ConnectTask.onPostExecute(MainActivity.java:111)
11-05 16:09:57.379: W/System.err(26675): at com.sanidhya.chatdemo.MainActivity$ConnectTask.onPostExecute(MainActivity.java:1)
11-05 16:09:57.380: W/System.err(26675): at android.os.AsyncTask.finish(AsyncTask.java:632)
11-05 16:09:57.380: W/System.err(26675): at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-05 16:09:57.380: W/System.err(26675): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
11-05 16:09:57.380: W/System.err(26675): at android.os.Handler.dispatchMessage(Handler.java:102)
11-05 16:09:57.380: W/System.err(26675): at android.os.Looper.loop(Looper.java:136)
11-05 16:09:57.380: W/System.err(26675): at android.app.ActivityThread.main(ActivityThread.java:5086)
11-05 16:09:57.380: W/System.err(26675): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 16:09:57.380: W/System.err(26675): at java.lang.reflect.Method.invoke(Method.java:515)
11-05 16:09:57.380: W/System.err(26675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-05 16:09:57.380: W/System.err(26675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-05 16:09:57.380: W/System.err(26675): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我现在开始工作了。实际上他们是 xml 响应中的问题。它没有头像或头像出现故障。我什至在保存头像时出现了错误的 base64。

通过以这种方式保存头像使其工作:

    private void uploadProfilePic() {
try {
Bitmap resized = Bitmap.createScaledBitmap(selected_img,128, 128,
true);
obj_UserInfo.setProfilePic(resized);
String get64BaseString = get64BaseString(resized);

VCard vCard = new VCard();

vCard.setAvatar(get64BaseString, "image/jpeg");
vCard.save(CGlobalVarriables.connection);
System.out.println("image upload successfuls");
CGlobalVarriables.obj_UserInfo.setProfilePic(resized);


} catch (Exception e) {
e.printStackTrace();
}
}

通过这种方式加载Vcard:

private Bitmap getProfilePic() {

VCard vCard = new VCard();
try {
vCard.load(CGlobalVarriables.connection);
byte[] array = vCard.getAvatar();
Bitmap bitmap = BitmapFactory.decodeByteArray(array, 0,
array.length);

return bitmap;

} catch (Exception e) {
e.printStackTrace();
}
return null;

}

关于调用 vcard.load(conn) 时 Android asmack vcard classcastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26752285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com