xiaomaguoguo / svg-android

Automatically exported from code.google.com/p/svg-android
1 stars 0 forks source link

java.lang.NumberFormatException: Invalid float: "1134.0pt" #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
com.larvalabs.svgandroid.SVGParseException: java.lang.NumberFormatException: 
Invalid float: "1134.0pt"
            at com.larvalabs.svgandroid.SVGParser.parse(Unknown Source)
            at com.larvalabs.svgandroid.SVGParser.getSVGFromInputStream(Unknown Source)
            at epaper.android.mineus.de.svgtest.SvgFragment.onCreateView(SvgFragment.java:31)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
            at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
            at android.view.View.measure(View.java:16497)
            at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
            at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
            at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
            at android.view.View.measure(View.java:16497)
            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:544)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NumberFormatException: Invalid float: "1134.0pt"
            at java.lang.StringToReal.invalidReal(StringToReal.java:63)
            at java.lang.StringToReal.parseFloat(StringToReal.java:310)
            at java.lang.Float.parseFloat(Float.java:300)
            at com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
            at com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
            at com.larvalabs.svgandroid.SVGParser.access$700(Unknown Source)
            at com.larvalabs.svgandroid.SVGParser$SVGHandler.startElement(Unknown Source)
            at org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:143)
            at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
            at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:513)
            at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.

Original issue reported on code.google.com by mineus....@gmail.com on 17 Jun 2014 at 7:26

GoogleCodeExporter commented 9 years ago
I had the same problem and fixed it.

In line 612 of SVGParser.java, I changed this line:

            if (v.endsWith("px")) {

to:

            if (v.endsWith("px") || v.endsWith("pt")) {

This check then is followed by a string op that cuts the last two characters 
off the number attribute before casting it to a float.

Original comment by skraman1...@gmail.com on 16 Jul 2015 at 2:54