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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:23:29+00:00 2026-06-11T17:23:29+00:00

I tried to add an array of textviews which i defined as a public

  • 0

I tried to add an array of textviews which i defined as a public variable, but when i run the application, it force closes as soon as it gets into for loop. This is the code:

LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
            LayoutParams lp = new LayoutParams( LayoutParams.WRAP_CONTENT,    LayoutParams.WRAP_CONTENT);
            pairs=new TextView[num_match+1];
            for(int l=1;l<=num_match;l++)
            {
                pairs[l].setTextSize(15);
                pairs[l].setLayoutParams(lp);
                pairs[l].setId(l);
                pairs[l].setText(m1[l]+" - "+m2[l]);
                myLayout.addView(pairs[l]);
            }
  • 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-11T17:23:30+00:00Added an answer on June 11, 2026 at 5:23 pm

    You need to create new TextViews to put into the TextView array and you are skipping the first index (pairs[0]) which will lead to trouble later:

    pairs=new TextView[num_match];
    for(int l=0; l<num_match; l++)
    {
        pairs[l] = new TextView(this);
        pairs[l].setTextSize(15);
        pairs[l].setLayoutParams(lp);
        pairs[l].setId(l);
        pairs[l].setText(m1[l + 1]+" - "+m2[l + 1]);
        myLayout.addView(pairs[l]);
    }
    

    From your comments, I included this simple working example to help you:

    public class Example extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
            LayoutParams lp = new LayoutParams( LayoutParams.WRAP_CONTENT,    LayoutParams.WRAP_CONTENT);
            TextView[] pairs=new TextView[4];
            for(int l=0; l<4; l++)
            {
                pairs[l] = new TextView(this);
                pairs[l].setTextSize(15);
                pairs[l].setLayoutParams(lp);
                pairs[l].setId(l);
                pairs[l].setText((l + 1) + ": something");
                myLayout.addView(pairs[l]);
            }
    
        }
    }
    

    With the layout main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add values from array to DB, have tried many variuos examples
I tried to add JRadioButton into JTable by using CellEditor and CellRenderer , but
I've tried the add() method but nothing is displayed when I try to add
In my view, there's an array of UIImageView. I tried to add panning gesture,
i have following array, and i have tried to add comma with the following
I have a sort function which was working fine but then I tried to
I tried storing data to php array from mysql using under code. But it's
Im trying to add an array to a webpage. I have tried a few
I tried to add search fields in Django using python. Followings are the codes
I tried some add to favorties JavaScript scripts.. With IE8, I get an access

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.