java.lang.IllegalArgumentException: org.jivesoftware.smack.packet.RosterPacket$ItemType is not an enum type
You are trying to use it (RosterPacket.ItemType) as an Enum, which it isn’t (in your version of smack? in my documentation of smack 3.0.4, it’s supposedly an Enum).
Some source code (using the code tags code here) that is causing this error would help understand the problem better.
//======== PacketReader.java (line: 679-698) ======
private RosterPacket parseRoster(XmlPullParser parser) throws Exception {
RosterPacket roster = new RosterPacket();
boolean done = false;
RosterPacket.Item item = null;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
String jid = parser.getAttributeValue("", "jid");
String name = parser.getAttributeValue("", "name");
// Create packet.
item = new RosterPacket.Item(jid, name);
// Set status.
String ask = parser.getAttributeValue("", "ask");
RosterPacket.ItemStatus status = RosterPacket.ItemStatus.fromString(ask);
item.setItemStatus(status);
// Set type.
String subscription = parser.getAttributeValue("", "subscription");
RosterPacket.ItemType type = RosterPacket.ItemType.valueOf(subscription);
item.setItemType(type); //==== RosterPacket.java (line:268-294) ======== public static enum ItemType { /**
* The user and subscriber have no interest in each other's presence.
*/
none, /**
* The user is interested in receiving presence updates from the subscriber.
*/
to, /**
* The subscriber is interested in receiving presence updates from the user.
*/
from, /**
* The user and subscriber have a mutual interest in each other's presence.
*/
both, /**
* The user wishes to stop receiving presence updates from the subscriber.
*/
remove
}
Okay. Your variable subscription could contain a String that isn’t a representative of a RosterPacket.ItemType.
From the docs:
valueOf
public static RosterPacket.ItemType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
To get around this uncertainty, surround the statement with a try-catch block, so you can take appropriate action (assign a default value, or give a better error message)…