AltBeacon / android-beacon-library-reference

A reference application for the Android Beacon Library
Apache License 2.0
275 stars 187 forks source link

NullPointerException: Identifiers cannot be constructed from null pointers but "stringValue" is null. #57

Closed prapkengr closed 5 years ago

prapkengr commented 5 years ago

From Beacon example ..

    @Override
    public void onBeaconServiceConnect() {
        // Set the two identifiers below to null to detect any beacon regardless of identifiers
        Identifier myBeaconNamespaceId = Identifier.parse("0x2f234454f4911ba9ffa6");
        Identifier myBeaconInstanceId = Identifier.parse("0x000000000001");

and so if I set

        Identifier myBeaconNamespaceId = Identifier.parse(null);
        Identifier myBeaconInstanceId = Identifier.parse(null);

Because, there is

    public static Identifier parse(String stringValue, int desiredByteLength) {
        if (stringValue == null) {
            throw new NullPointerException("Identifiers cannot be constructed from null pointers but \"stringValue\" is null.");
davidgyoung commented 5 years ago

How does this behavior differ than what you expect, or think it should be?

prapkengr commented 5 years ago

How does this behavior differ than what you expect, or think it should be?

I followed the comment (Beacon sample) .. says // Set the two identifiers below to null to detect any beacon regardless of identifiers So,

        Identifier myBeaconNamespaceId = Identifier.parse(null);
        Identifier myBeaconInstanceId = Identifier.parse(null);

And it crashes on the app run, saying, NullPointerException: Identifiers cannot be constructed from null pointers but "stringValue" is null. But, Yes, of course, then, now, I found identifiers to be parsed. There is no issue for me to do it with identifiers. Only point is .. the purpose of "Set the two identifiers below to null to detect any beacon regardless of identifiers" is not served.

davidgyoung commented 5 years ago

Are you referring to the docs on this page?

https://altbeacon.github.io/android-beacon-library/eddystone-how-to.html

        // Set the two identifiers below to null to detect any beacon regardless of identifiers
        Identifier myBeaconNamespaceId = Identifier.parse("0x2f234454f4911ba9ffa6");
        Identifier myBeaconInstanceId = Identifier.parse("0x000000000001");
        Region region = new Region("my-beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);

If so, then the correct way to set the identifiers to null is like this:

       Region region = new Region("my-beacon-region", null, null, null);

Note you just pass null values for Identifier in the Region constructor. There is no reason to use the Identifier.parse method, which indeed throws an exception if you pass a null value.

prapkengr commented 5 years ago

Region region = new Region("my-beacon-region", null, null, null);

Perfect. Thanks !