jianzhongli / MathView

A library for displaying math formula in Android apps.
Apache License 2.0
1.01k stars 189 forks source link

Mathview setText causing java.lang.StringIndexOutOfBoundsException #44

Open donpeter06 opened 7 years ago

donpeter06 commented 7 years ago

This is the value that i try to set in mathview

(\ N{0}/2 ) atoms of X(g) are converted into (\ X^{+}(g) ) by energy (\ E{1} ). (\ N{0}/2 ) atoms of X(g) are converted into (\ X^{-}(g) ) by energy (\ E{2} ). Hence, ionisation potential and electron affinity of X (g) are

This causes an exception

java.lang.StringIndexOutOfBoundsException: length=0; index=0 at java.lang.String.charAt(Native Method) at com.x5.template.providers.TemplateProvider.parseEmbeddedExtension(TemplateProvider.java:117) at com.x5.template.providers.TemplateProvider.resourceName(TemplateProvider.java:91) at com.x5.template.providers.TemplateProvider.loadItemDoc(TemplateProvider.java:80) at com.x5.template.providers.TemplateProvider.getSnippet(TemplateProvider.java:43) at com.x5.template.providers.TemplateProvider.provides(TemplateProvider.java:29) at com.x5.template.Theme.getSnippet(Theme.java:194) at com.x5.template.Chunk.altFetch(Chunk.java:955) at com.x5.template.Chunk.altFetch(Chunk.java:858) at com.x5.template.Chunk._resolveTagValue(Chunk.java:1038) at com.x5.template.Chunk.resolveTagValue(Chunk.java:1009) at com.x5.template.SnippetTag.render(SnippetTag.java:43) at com.x5.template.Snippet.render(Snippet.java:843) at com.x5.template.SnippetTag.render(SnippetTag.java:50) at com.x5.template.Snippet.render(Snippet.java:843) at com.x5.template.Chunk.explodeToPrinter(Chunk.java:728) at com.x5.template.Chunk.renderForParentToPrinter(Chunk.java:689) at com.x5.template.Chunk.explodeForParentToPrinter(Chunk.java:681) at com.x5.template.Chunk.render(Chunk.java:643) at com.x5.template.Chunk.toString(Chunk.java:612) at io.github.kexanie.library.MathView.setText(MathView.java:69)

donpeter06 commented 7 years ago

Looks like MathView is not capable of parsing X^{+}. this part is actually causing the crash

yaxhpal commented 6 years ago

@donpeter06 I got the same issue and your diagnosis was spot on. I have expression \(Li^{+}\) which was causing the above exception. My question is - did you resolve this issue? How do I change my expression so that I do not get this exception while keeping the rendered expression as much similar as the original one.

finotes commented 6 years ago

@yaxhpal Nope. I ditched the native development for webview based display.

yaxhpal commented 6 years ago

@finotes That's okay. The workaround which worked for me is - I have removed the braces for single plus sign i.e., ^{+} --> ^+. Other cases like ^{+1} or ^{+x} work fine without modification.

techbhaskar commented 5 years ago

try to replace "^" , "-", "+" with ascii codes like hat,45,43 image after that its work in MathView image

techbhaskar commented 5 years ago

Looks like MathView is not capable of parsing X^{+}. this part is actually causing the crash

You saved alot of time for me , Thank u so much