ohshi000 / androidsvg

Automatically exported from code.google.com/p/androidsvg
0 stars 0 forks source link

SVGImageView throws NullPointerException if no asset is defined in layout. #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use an SVGImageView in an xml layout.
2. Don't define the svg attribute since you want to specify the image later, 
programmatically. This is a feature that ImageView has.

What is the expected output? What do you see instead?

I expect the SVGImageView to show up empty if setImageAsset() is NOT called 
programmatically. It it is called I expect the specified image to show.

Instead the app crashes since SVGImageView.java:81 tries to parse a null "url" 
and throws NullPointerException.

What version of the product are you using? On what operating system?

1.2 I believe. I cloned the repo today.
Android 2.3.3 (API 10)

Please provide any additional information below.

The exception is being thrown because not specifying the svg attribute in the 
xml when declaring an SVGImageView means line 80 of SVGImageView.java:

String url = a.getString(R.styleable.SVGImageView_svg);

returns url equal to null. But this is expected behaviour. The view should just 
shrug this off and wait for setImageAsset() or something similar to be called 
later.

Solution:

Wrap lines 81-87 in an if statement that verifies that (url != null) before 
continuing inside. I implemented this change and the app worked flawlessly.

Original issue reported on code.google.com by a...@spoton.com on 31 Oct 2013 at 7:59

GoogleCodeExporter commented 8 years ago
Thanks for the report.  Clearly I didn't test SVGImageView as well as I should 
have. :)

Original comment by paul.leb...@gmail.com on 31 Oct 2013 at 8:03

GoogleCodeExporter commented 8 years ago
Fixed in local revision 271.

Fixed NPE in SVGImageView if no "svg" parameter provided in XML.

This fix will be in the next release (1.3).

Original comment by paul.leb...@gmail.com on 31 Oct 2013 at 8:11

GoogleCodeExporter commented 8 years ago
This fix is available in the 1.2.1 release.

Original comment by paul.leb...@gmail.com on 31 Jan 2014 at 1:32