In my Android app I've got this method which takes a UUID. Unfortunately when I do this:
OverviewEvent overviewevent = eventAdapter.getOverviewEvent(UUID.fromString("0f14d0ab-9605-4a62-a9e4-5ed26688389b"));
I get an error saying java.lang.IllegalArgumentException: Invalid UUID: 100
The implementation of the getOverviewEvent is as follows:
public OverviewEvent getOverviewEvent(UUID uuid) throws Exception {
// Do stuff
}
Does anybody know how I can solve this?
The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. Syntax: public static UUID fromString(String UUID_name)
UUID uuid = UUID. randomUUID(); The third static method returns a UUID object given the string representation of a given UUID: UUID uuid = UUID.
A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. There exist different variants of these global identifiers.
Here is a workaround which avoids using this method,
String s = "0f14d0ab-9605-4a62-a9e4-5ed26688389b";
String s2 = s.replace("-", "");
UUID uuid = new UUID(
new BigInteger(s2.substring(0, 16), 16).longValue(),
new BigInteger(s2.substring(16), 16).longValue());
System.out.println(uuid);
prints
0f14d0ab-9605-4a62-a9e4-5ed26688389b
Did you copy and paste the code, I have found that a few characters that look correct are in fact the wrong ACSII code.
Remove the - and replace them again.
I have had this often with " as different editors/computers may use a slightly different code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With