Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:19:12+00:00 2026-06-02T20:19:12+00:00

I’m using sax parser to get xml data, the below code is causing my

  • 0

I’m using sax parser to get xml data, the below code is causing my app to crash.

    try {
        url = new URL("The URL");
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
   // RssFeed feed = null;
    try {
        feed = RssReader.read(url);
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Looks like it is crashing at feed = RssReader.read(url); It works fine on my evo but when I install it on my hero the below error occurs

04-28 15:57:53.458: E/AndroidRuntime(2749): Uncaught handler: thread main exiting due to uncaught  exception
04-28 15:57:53.589: E/AndroidRuntime(2749): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mlgw.mlgwapp/com.mlgw.mlgwapp.TipsActivity}: java.lang.StringIndexOutOfBoundsException
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2411)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:379)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.View.performClick(View.java:2364)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.View.onTouchEvent(View.java:4179)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.View.dispatchTouchEvent(View.java:3709)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.os.Looper.loop(Looper.java:123)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.ActivityThread.main(ActivityThread.java:4595)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at java.lang.reflect.Method.invoke(Method.java:521)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at dalvik.system.NativeStart.main(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749): Caused by: java.lang.StringIndexOutOfBoundsException
04-28 15:57:53.589: E/AndroidRuntime(2749):     at java.lang.String.substring(String.java:1646)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at nl.matshofman.saxrssreader.RssHandler.endElement(RssHandler.java:67)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:159)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatParser.append(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at nl.matshofman.saxrssreader.RssReader.read(RssReader.java:43)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at com.mlgw.mlgwapp.TipsActivity.onCreate(TipsActivity.java:57)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-28 15:57:53.589: E/AndroidRuntime(2749):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)

Please Help!!

Here is my RssHandler class

package nl.matshofman.saxrssreader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

public class RssHandler extends DefaultHandler {

private RssFeed rssFeed;
private RssItem rssItem;
private StringBuilder stringBuilder;

@Override
public void startDocument() {
    rssFeed = new RssFeed();
}

/**
 * Return the parsed RssFeed with it's RssItems
 * @return
 */
public RssFeed getResult() {
    return rssFeed;
}

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    stringBuilder = new StringBuilder();

    if(qName.equals("item") && rssFeed != null) {
        rssItem = new RssItem();
        rssItem.setFeed(rssFeed);
        rssFeed.addRssItem(rssItem);
    }
}

@Override
public void characters(char[] ch, int start, int length) {
    stringBuilder.append(ch, start, length);
}

@Override
public void endElement(String uri, String localName, String qName) {

    if(rssFeed != null && rssItem == null) {
        // Parse feed properties

        try {
            String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1);
            Method method = rssFeed.getClass().getMethod(methodName, String.class);
            method.invoke(rssFeed, stringBuilder.toString());
        } catch (SecurityException e) {
        } catch (NoSuchMethodException e) {
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        }

    } else if (rssItem != null) {
        // Parse item properties

        try {
            if(qName.equals("content:encoded")) 
                qName = "content";
            String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1);
            Method method = rssItem.getClass().getMethod(methodName, String.class);
            method.invoke(rssItem, stringBuilder.toString());
        } catch (SecurityException e) {
        } catch (NoSuchMethodException e) {
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        }
    }

}

}
ok I added that now there is this

04-28 18:49:35.189: E/AndroidRuntime(3780): Uncaught handler: thread main exiting due to uncaught exception
04-28 18:49:35.328: E/AndroidRuntime(3780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mlgw.mlgwapp/com.mlgw.mlgwapp.TipsActivity}: java.lang.IllegalArgumentException
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2411)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:379)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.View.performClick(View.java:2364)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.View.onTouchEvent(View.java:4179)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.View.dispatchTouchEvent(View.java:3709)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.os.Looper.loop(Looper.java:123)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.ActivityThread.main(ActivityThread.java:4595)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at java.lang.reflect.Method.invoke(Method.java:521)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at dalvik.system.NativeStart.main(Native Method)
04-28 18:49:35.328: E/AndroidRuntime(3780): Caused by: java.lang.IllegalArgumentException
04-28 18:49:35.328: E/AndroidRuntime(3780):     at java.util.Random.nextInt(Random.java:221)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at com.mlgw.mlgwapp.TipsActivity.onCreate(TipsActivity.java:71)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-28 18:49:35.328: E/AndroidRuntime(3780):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
04-28 18:49:35.328: E/AndroidRuntime(3780):     ... 30 more

Now seems to have somethig to do with the round function I’m using.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:19:16+00:00Added an answer on June 2, 2026 at 8:19 pm

    The stacktrace tells you the cause of the error:

    Caused by: java.lang.StringIndexOutOfBoundsException
         at java.lang.String.substring(String.java:1646)
         at nl.matshofman.saxrssreader.RssHandler.endElement(RssHandler.java:67)
    

    The actual error happens in java.lang.String.substring() which is not your code so you can’t fix anything there. But the next line tells you where substring was called. RssHandler.java in line 67, in method endElement

    That should be:

    String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1)
    

    String indexes are their characters so you access qName although it is empty and you can’t build a substring from just the first character or starting after the first character.

    To prevent the crash you can do

    if (qName != null && qName.length() > 0) {
        String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1);
        Method method = rssFeed.getClass().getMethod(methodName, String.class);
        method.invoke(rssFeed, stringBuilder.toString());
    }
    

    and you should have a look at the XML and find out why there is a qName that does not fit the expected format.

    Also localName might be better to check since the qualified name of <xsl:template /> is xsl:template while the local name is just template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.