d may be null. So we need a null check before calling d.setBounds(). And if d==null, it should log an error, something like "Unable to create drawable from path: xxxxx" .