ClassCastException when trying to get additional information on MUC Users

I am currently devloping an Smack-based XMPP client with MUC-support and i am got the following problem:

When trying to recieve the list of current Participants with MultiUserChat.getParticipants() I run into the following Exception:

java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to org.jivesoftware.smackx.packet.MUCAdmin

at org.jivesoftware.smackx.muc.MultiUserChat.getOccupants(MultiUserChat.java:1943)

at org.jivesoftware.smackx.muc.MultiUserChat.getParticipants(MultiUserChat.java:20 12)

However using MultiUserChat.getOccupants() works - but not getOccupant(fulljid) (nearly same as above)

I could repeat this issue with several Servers with different software - so it is a client problem.

Any help would be great

It looks like your META-INF/smack.providers file is not on your classpath.

Thanks! That did it.

Could you please explain how to do that?
I have asmack-android-18-0.8.9.jar included in my project but there is only MANIFEST.MF file in META-INF folder.

In case of aSmack you simply need to run the static intializer like the README tells you to do.

Thanks for the quick answer. But I already initialize SmackAndroid on startup as follows:

SmackAndroid.init(context);

Is there anything else I need to do in order to register Smack’s XMPP Providers and Extensions?

Thanks

No, could you show use a full stacktrace and the relevant code?

MultiUserChat muc2 = new MultiUserChat(connection, roomName+"@"+serviceName);

DiscussionHistory history = new DiscussionHistory();

history.setMaxStanzas(5);

muc2.join(nickName, null, history,SmackConfiguration.getPacketReplyTimeout());

//After joining room, I try to get the room info and member list

RoomInfo info = MultiUserChat.getRoomInfo(connection, roomName + “@” + serviceName);

Log.i(TAG,“Number of occupants:” + info.getOccupantsCount());

Log.i(TAG,“Room Subject:” + info.getSubject());

Collection members = muc2.getMembers(); //LINE 442 IS HERE

for(Affiliate member:members)

Log.i(TAG,“Room member:” + member.getNick() + " - " +member.getJid());

When I run this, the resulting logcat output is as follows:

I/XMPPManager(4210): Number of occupants:2

I/XMPPManager(4210): Room Subject:

E/AndroidRuntime(4210): FATAL EXCEPTION: main

E/AndroidRuntime(4210): java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to org.jivesoftware.smackx.packet.MUCAdmin

E/AndroidRuntime(4210): at org.jivesoftware.smackx.muc.MultiUserChat.getAffiliatesByAdmin(MultiUserChat.ja va:1750)

E/AndroidRuntime(4210): at org.jivesoftware.smackx.muc.MultiUserChat.getMembers(MultiUserChat.java:1672)

E/AndroidRuntime(4210): at com.firatdulger.deneme.xmpp.muc.XMPPManager.joinRoom(XMPPManager.java:442)

E/AndroidRuntime(4210): at com.firatdulger.deneme.xmpp.muc.MainActivity$4.onClick(MainActivity.java:103)

E/AndroidRuntime(4210): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertContr oller.java:166)

E/AndroidRuntime(4210): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime(4210): at android.os.Looper.loop(Looper.java:137)

E/AndroidRuntime(4210): at android.app.ActivityThread.main(ActivityThread.java:4424)

E/AndroidRuntime(4210): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime(4210): at java.lang.reflect.Method.invoke(Method.java:511)

E/AndroidRuntime(4210): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

E/AndroidRuntime(4210): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

E/AndroidRuntime(4210): at dalvik.system.NativeStart.main(Native Method)

Message was edited by: Fırat Dülger

The provider for the MUCAdmin packaet is not loaded. I can’t tell why from the info I have. This is usually caused by not calling SmackAndroid.init() in aSmack, which will load the provider:

// MUC Admin

    pm.addIQProvider("query","[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)", new MUCAdminProvider());

Your best chance is to debug why the provider isn’t used.