Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caused by: java.lang.StringIndexOutOfBoundsException: length=599; regionStart=181; regionLength=-104 #1

Closed
Mardoqueu opened this issue Apr 22, 2015 · 2 comments

Comments

@Mardoqueu
Copy link

I loved it, your rss reader, it's really great! I changed to test another RSS and worked great, but after it read the rss appered a list of news and when I click on one of them, I am getting this message, it's not every single news, but in some news. Do you know what is it?
I thought I needed change the values length=599; regionStart=181; regionLength=-104, but I didn't find yet exactly where they are. This is the link I am using for feeding: https://ajax.googleapis.com/ajax/services/feed/load?v=2.0&num=10&q=http://g1.globo.com/dynamo/rss2.xml

Thank you ever so much

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{ua.ck.geekhub.prozapas.ghprozapasrssreader/ua.ck.geekhub.prozapas.ghprozapasrssreader.activities.DetailsActivity}: java.lang.StringIndexOutOfBoundsException: length=599; regionStart=181; regionLength=-104
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
at android.app.ActivityThread.access$600(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4793)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.StringIndexOutOfBoundsException: length=599; regionStart=181; regionLength=-104
at java.lang.String.startEndAndLength(String.java:593)
at java.lang.String.substring(String.java:1474)
at ua.ck.geekhub.prozapas.ghprozapasrssreader.fragments.DetailsFragment.onViewCreated(DetailsFragment.java:92)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:843)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.BackStackRecord.run(BackStackRecord.java:635)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
at android.app.Activity.performStart(Activity.java:5017)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
            at android.app.ActivityThread.access$600(ActivityThread.java:133)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4793)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
            at dalvik.system.NativeStart.main(Native Method)
04-22 13:45:43.977 8134-8136/ua.ck.geekhub.prozapas.ghprozapasrssreader D/dalvikvm﹕ GC_CONCURRENT freed 517K, 10% free 7210K/8007K, paused 13ms+2ms, total 39ms

@Allteran
Copy link
Owner

Hello, Mardoqueu. Thank you so much for an report and I'm really grateful to you that you are using my RssReader!
If I'm not wrong, you are having an error on this

String contentWithoudImage = mRssItem.getContent().replace(mRssItem.getContent().substring(mRssItem.getContent().lastIndexOf("<img"), mRssItem.getContent().indexOf("br") + 4), "");

This line should delete "blue rectangle" that appears, when you parse from HTML simple text with image inside and set it to the TextView. In my case - there are always was images inside of the contentfield of JSON structure. In your case there are more then ome link and sometimes you have no any links incontent field. I reccomend you just to delete string contentWithoutImageand in textViewDescriptionjust set textViewDescription.setText(Html.fromHtml(mRssItem.getContent())). Or replace 93-d line of code in DetailsFragment.java with

String contentWithoudImage = mRssItem.getContent().replace(mRssItem.getContent().substring(mRssItem.getContent().lastIndexOf("<img"), mRssItem.getContent().indexOf("br") + 3), "");

Please. let me know if this helped you.
I am really glad to help you in any issue :)

@Mardoqueu
Copy link
Author

It worked for me, thanks a lot!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants