InputStream不返回找到的元素错误

时间:2017-04-03 20:45:26

标签: android image parsing url svg

我正在关注这个例子 android:load svg file from web and show it on image view

这是我正在使用的代码。它基本上是他们正在做的事情的副本。但我一直得到错误,找不到元素。

class FetchImageTask extends AsyncTask<Void, Void, Drawable> {

    protected Drawable doInBackground(Void... urls) {
        try {
            //URL url = new URL(imageTeam);
            final URL url = new URL("http://upload.wikimedia.org/wikipedia/commons/e/e8/Svg_example3.svg");
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            SVG svg = SVGParser.getSVGFromInputStream(inputStream);
            Drawable drawable = svg.createPictureDrawable();
            return drawable;

        } catch (Exception e) {
            Log.e("MainActivity", e.getMessage(), e);
        }
        return null;
    }

    protected void onPostExecute(Drawable drawable) {
        if (drawable != null) {

            team1.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            team1.setImageDrawable(drawable);
            team1.setVisibility(View.VISIBLE);
        }
    }


}

这是我的错误日志。

75-24781/com.example.fahs08.project E/MainActivity: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
                                                                      com.example.fahs08.project.svgandroid.SVGParseException: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
                                                                          at com.example.fahs08.project.svgandroid.SVGParser.parse(SVGParser.java:207)
                                                                          at com.example.fahs08.project.svgandroid.SVGParser.getSVGFromInputStream(SVGParser.java:76)
                                                                          at com.example.fahs08.project.MainActivity$FetchImageTask.doInBackground(MainActivity.java:172)
                                                                          at com.example.fahs08.project.MainActivity$FetchImageTask.doInBackground(MainActivity.java:164)
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:305)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                          at java.lang.Thread.run(Thread.java:761)
                                                                       Caused by: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
                                                                          at org.apache.harmony.xml.ExpatParser.finish(ExpatParser.java:545)
                                                                          at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:475)
                                                                          at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
                                                                          at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
                                                                          at com.example.fahs08.project.svgandroid.SVGParser.parse(SVGParser.java:198)
                                                                          at com.example.fahs08.project.svgandroid.SVGParser.getSVGFromInputStream(SVGParser.java:76) 
                                                                          at com.example.fahs08.project.MainActivity$FetchImageTask.doInBackground(MainActivity.java:172) 
                                                                          at com.example.fahs08.project.MainActivity$FetchImageTask.doInBackground(MainActivity.java:164) 
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:305) 
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                          at java.lang.Thread.run(Thread.java:761) 

非常感谢任何帮助!

0 个答案:

没有答案