Francisco Romero
Francisco Romero

Reputation: 13199

"Exception while parsing XML file: Premature end of file." trying to import svg to Android Studio

I am trying to import a svg file to Android Studio and I am getting the following error:

Could not generate a preview

EXCEPTION in parsing prove.svg:

For input string: "60px"Exception while parsing XML file:

Premature end of file.

And this is the svg that I have by the moment:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="150" height="150">
  <circle r="60px" fill="red" cx="90" cy="65"></circle>
</svg>

As you can see, I do not have any problems if I use it on the net because it is rendering well.

So, what am I missing? Should I adapt it to some format to use it on Android Studio?

Note: I have searched and it seems that it had to be adapted on old versions of Android Studio because it did not accept <circle> tags but I also have saw that now it should accept them. Now I am using Android Studio 2.2.

Thanks in advance!

Upvotes: 0

Views: 3135

Answers (2)

AlphaQ
AlphaQ

Reputation: 676

Well, you can try this SVG approach here:

<svg height="100" width="100">
   <circle cx="50" cy="50" r="40" fill="red" />
</svg>

Or, the better and scalable vector approach:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="oval">
  <solid
    android:color="#ff0000"/>
</shape>

HInt: Since the vector method is recommended, there are tools online that can convert SVG to Vector graphics for complex curves and paths.

Upvotes: 1

Dave S
Dave S

Reputation: 3468

It doesn't directly answer your question but if you want to have a vector based circle in Android, I highly recommend the drawable approach seen in the below answer.

https://stackoverflow.com/a/34724737/2680506

Upvotes: 0

Related Questions