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

  • Home
  • SEARCH
  • 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 8957449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:59:34+00:00 2026-06-15T14:59:34+00:00

I have an arrayoutofboundsexception error in my 2 column listview, please check my code

  • 0

I have an arrayoutofboundsexception error in my 2 column listview,

please check my code below:

    private static ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.meal_result);

    BreakFastLog info = new BreakFastLog(this);
    info.open();

    String data1 = info.getMealNameData();
    String data2 = info.getServingData();

    String[] inputData = data1.split( " " );
    String[] inputData2 = data2.split( " " );

    lv = (ListView) findViewById (R.id.lvBF);   

    /*
    ArrayList<HashMap<String, String>> mylistData =
            new ArrayList<HashMap<String, String>>();

    int[] columnIds = new int[] {
            R.id.tvBreakfastMealContainer, R.id.tvBreakfastServingContainer};

    HashMap<String, String> map = new HashMap<String, String>();
    //initialize row data
    map.put( "Meal", data1 );
    map.put( "Serving", data2 );
    mylistData.add( map );

    //lv.setAdapter( new ArrayAdapter<String>( this,android.R.layout.simple_list_item_1, inputData ) );

    //SimpleAdapter arrayAdapter =
    //           new SimpleAdapter(this, mylistData, R.layout.breakfast_listview_header,
    //                   new String[] {"Meal", "Serving"}, columnIds);
    //lv.setAdapter(arrayAdapter);   */
    lv.setAdapter( new MyCustomAdapter( inputData, inputData2 ) );

    lv.setTextFilterEnabled( true ); 

    info.close();

}

class MyCustomAdapter extends BaseAdapter
{

       String[] data_meal;
       String[] data_serving;

 MyCustomAdapter()
 {
       data_meal = null;
       data_serving = null;
 }

 MyCustomAdapter( String[] meal, String[] serving )
 {
       data_meal = meal;
       data_serving = serving;
 }

 public int getCount()
 {
       return data_meal.length;
 }

 public String getItem( int position )
 {
       return null;
 }

 public long getItemId( int position )
 {
       return position;
 }

 public View getView( int position, View convertView, ViewGroup parent )
 {

       LayoutInflater inflater = getLayoutInflater();
       View row;

       row = inflater.inflate( R.layout.breakfast_listview_header, parent, false );

       TextView txtMeal = ( TextView ) row.findViewById ( R.id.tvBreakfastMealContainer );
       TextView txtServing = ( TextView ) row.findViewById ( R.id.tvBreakfastServingContainer );

       txtMeal.setText( data_meal[ position ] );
       txtServing.setText( data_serving[ position ] );

       return (row);

     }
 }

please help me figure out what went wrong. Thanks.

  • 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-15T14:59:35+00:00Added an answer on June 15, 2026 at 2:59 pm

    While it will not fix the error this code should help you find out where its going wrong.

    Try tweaking your getView() method to something like this:

    public View getView( int position, View convertView, ViewGroup parent )
    {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate( R.layout.breakfast_listview_header, parent, false );
    
        TextView txtMeal = ( TextView ) row.findViewById ( R.id.tvBreakfastMealContainer );
        TextView txtServing = ( TextView ) row.findViewById ( R.id.tvBreakfastServingContainer );
    
        if (position > data_meal.length)
        {
            txtMeal.setText(data_meal[position]);
        ]
        else
        {
            txtMeal.setText("MISSING!!");
        }
    
        if (position > data_serving.length)
        {
            txtServing.setText(data_serving[position]);
        ]
        else
        {
            txtServing.setText("MISSING!!");
        }
    
        return row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a painfully simple blog Post creator, and I'm trying to check if the
Have some code: using (var ctx = new testDataContext()) { var options = new
Have a look at the following code to find X^y. /* Find exponent in
Have have this line of code in my form when I create a new
have a php code like this,going to convert it in to C#. function isValid($n){
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have the following code: String s= v.request(engine/?key=, P4z72NmBa91&method=load); JSONParser parser = new JSONParser(); Object
Have got the following HAML code, combined with Markdown: %h2.slogan.align-center :markdown No more big
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.