Question

I have a simple Glass app using the GDK to grab some text & take a photo. I can easily create a LiveCard w/ the text & photo, however when I try to convert the live card to a static card, I get a null pointer exception when I try to add the image to the card. here's a snippet of my code. If i remove the call to addImage() it posts the card just fine.

        Card c = new Card(CompPlayerService.this);
        c.setText("you took a picture of " + MyService.this.personName);
        Uri uri = Uri.parse(picturePath); 
        c.addImage( uri);  //<-- this is throwing the NPE
        timelineManager.insert(c);

When I set a breakpoint in the service, I can see that the value of picturePath is NOT null and is the same exact path I use when I post the photo to a live card from the same service, which works fine. here's the exception I get:

02-17 15:32:25.049  14120-14120/com.example.glassapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at com.google.android.glass.app.Card.addImage(Card.java:176)
Was it helpful?

Solution

What is the value of picturePath? My hunch is that you're passing a simple filesystem path instead of a valid file: URI.

You may want to consider using the Uri.fromFile method instead of Uri.parse to handle this correctly.

UPDATE: The Card class no longer supports calling addImage with a Uri argument. Instead, load the image into a Bitmap and call addImage(Bitmap).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top