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 6618413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:49:48+00:00 2026-05-25T20:49:48+00:00

I am trying to get the bold text next to the hour scheldule (

  • 0

I am trying to get the bold text next to the hour scheldule ( from http://golfnews.no/golfpaatv.php )put it in a String array , then , show it on my device’s screen. I’ve put the Internet Access permission , so that is not the problem.The application crashes on my device . Reason : index out of bounds . I don’t understand where’s the problem . My code is :

package com.work.webrequest;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class WebRequest extends Activity {


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String trax;

        String aux[] = new String[10];

        setContentView(R.layout.main);
        TextView txt = (TextView) findViewById(R.id.textView1);
        trax=getPage();

       aux= title (trax);


       txt.setText(" Here I will display every title!!!");

    }
    private String[] title (String trax)
    {

        String result[] = new String[10];
        int ok=1;
        int s1,s2;
        int i=0;
        while(ok==1)
        {
            System.out.println("INDEX = "+trax.indexOf("<h2>"));
            ok=0;
            if(trax.indexOf("<h2>")!=-1)
            {


            ok=1;
            s1 =trax.indexOf("<h2>");
            s2 = trax.indexOf("</h2>");
            result[i] = trax.substring(s1+4,s2);
            i++;
            trax = trax.substring(trax.indexOf("</h2>"));

            }

        }
         return result;
    }

    private String getPage() {
        String str = "***";

        try
        {
            HttpClient hc = new DefaultHttpClient();
            HttpPost post = new HttpPost("http://www.golfnews.no/feed.php?feed=1");
            HttpResponse rp = hc.execute(post);

            if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            {
                str = EntityUtils.toString(rp.getEntity());
            }
        }catch(IOException e){
            e.printStackTrace();
        }  

        return str;
    }


}

The number of <h2> and </h2> is below 10 . My application crashes at the 2nd iteration . I am a beginner in android , so I don’t know much . Could you give me a hint ? I would really appreciate it . Thank you !

PS : I know what Index Out of bounds means , I just don’t know why I get the error here .

  • 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-05-25T20:49:48+00:00Added an answer on May 25, 2026 at 8:49 pm

    You get IndexOutOfBoundsException when you want to access an array index which is out of range. For example:

    String[] myArray = new String[10];
    myArray[10] = "test"; // 10 is out of limits(0-9)
    

    Would produce such an exception. Check the stacktrace for the line that this exception originates from. It tells you the class name/method name/line number that this problem comes from.

    In your case I suspect there are more than 10 <h2> in the trax, so you get this exception.

    Initially you don’t know the number of <h2>‘s so change this line:

    String result[] = new String[10];
    

    with this:

    ArrayList<String> result= new ArrayList<String>(); 
    

    Then you can add elements to this list with the following:

    // result[i] = trax.substring(s1+4,s2);
    result.add(trax.substring(s1+4,s2));
    

    EDIT1
    Also I think you mean this:

    //trax = trax.substring(trax.indexOf("</h2>"));
    trax = trax.substring(s2 + 5);
    

    EDIT2

    Also I realized you allocate arrays wrong, you are allocating a String of 10 chars instead of an array of 10 Strings:

    //String aux[] = new String[10];
    String[] aux = new String[10];
    
    //String result[] = new String[10];
    String[] result = new String[10];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make some text bold using HTML, but I'm struggling to get
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm trying add a bold/strong tag the line headings of the follow string/text block:
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
trying to get some data from a plist into the MWPhotoBrowser sample app. Any
I'm trying to find the physical pixel size of a string of text. I
I am trying to get the Sample text of a font.This is my coding.
I'm trying to get some of the text in message for my UIAlertView to

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.