0

I have met problems dealing with the SVG-android library. In my main activity I want to display the SVG object on the imageview however, i am facing this error.

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.androidsvgdemo/com.example.androidsvgdemo.MainActivity}:
com.larvalabs.svgandroid.SVGParseException: 
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: not well-formed (invalid token)

My codes are as follows:

package com.example.androidsvgdemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGParser;

import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;

public class MainActivity extends Activity {

    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView)findViewById(R.id.img1);
        //Parse the SVG file from the resource
        SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.imageandroid);
        //Get a drawable from the parsed SVG and apply to ImageView
        imageView.setImageDrawable(svg.createPictureDrawable());

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

Please advice. Thank you.

Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
pancakeleh
  • 70
  • 1
  • 2
  • 11

1 Answers1

0

The error indicates that the SVG file is malformed XML... You'll need to edit it with Inkskape and save it again. This should repare your SVG file.

avianey
  • 5,545
  • 3
  • 37
  • 60
  • unfortunatelly it doesn't seem to read Inkscape svg files, try this: http://www.clker.com/cliparts/C/G/j/0/u/S/animal-number-one.svg – Gavriel Mar 01 '14 at 19:17
  • your file use that are not compatible with svg basic, also, try to remove the groups from your svg and the transform : translate and matrix applied to ... – avianey Mar 02 '14 at 12:29
  • it's not my file, that's the source of the problem. I could maybe pre-process them, if there's some command-line tool that can do that. Do you know any? – Gavriel Mar 02 '14 at 12:53
  • this is another problem... Inkscape doesn't provide a way to save an svg file as SVG Basic (you can do it with illustrator). The file you try to use contains matrix transform and inkscape don't know how to remove it. You can open the file and use 1) select all CTRL+SHIFT+A 2) ungroup all CTRL+SHIFT+G many times 3) simplify path CTRL+L 4) save the file. This will remove the matrix tranform too... but some path will be altered (bezier curves). The best solution for you is to use Illustrator. – avianey Mar 02 '14 at 13:21