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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:13:02+00:00 2026-06-11T22:13:02+00:00

After reading some similiar problem here, I’m still forced to post my question here.

  • 0

After reading some similiar problem here, I’m still forced to post my question here.

I have an Activity that should add and show a certain amount of Buttons relative to an amount of games in my SQLite-database. This Activity must be scrollable.

So i have my basic layout-xml-file like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:paddingLeft="15dp"
    android:paddingRight="15dp" >
    <RelativeLayout 
        android:id="@+id/rel_all_football" 
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"        
        >

        <TextView 
            style="@style/TextHeader"
            android:id="@+id/tv_all_football_header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/all_games"
            />
        <View   
            android:id="@+id/v_cond_line1"
            android:layout_below="@+id/tv_all_football_header"
            android:layout_height="1dp"
            android:layout_width="fill_parent"
            android:layout_marginBottom="10dp"
            android:background="#FFFFFF"
            />
    </RelativeLayout>

</ScrollView>

Now for every entry in the database, I want to add a Button with the certain information in that RelativeLayout under the TextView (header) and the View (simple line).

So after reading some questions here, I tried something like this:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.rel_all_football);

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        Button button;
        for(int i=0; i<3; i++){
            button = new Button(this);
            button.setLayoutParams(
                    new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
                                     ViewGroup.LayoutParams.WRAP_CONTENT));
            button.setText("Hello " + i);

            layout.addView(button);
        }

This is causing a NullPointerException at layout.addView(button). To tell the truth, it’s the first time I’m trying to add content from code and not directly in xml, so I have no clue if I’m doing this right. I know that a View must have at least the attributes layout_width and layout_height declared, so what is wrong here? Am I inflating wrong? Or do I find the error in the creation of the Button?

  • 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-11T22:13:04+00:00Added an answer on June 11, 2026 at 10:13 pm

    i think you are facing some problem with id’s sotTry this

    ScrollView scrollView = (ScrollView)getLayoutInflater().inflat(R.layout.filename)
            RelativeLayout layout = (RelativeLayout) scrollView.findViewById(R.id.rel_all_football);
            Button button;
            for(int i=0; i<3; i++){
                button = new Button(this);
                button.setLayoutParams( new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                button.setText("Hello " + i);
    
                layout.addView(button);
            }
    
        setContentView(scrollView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some reading and R&D, I have came to conclusion that ? Forms in
After reading some material on this subject I'm still not sure what the difference
After reading some articles about XSS I have incorporated HTMLPurifier into my zend framework
Say I have a connection to a database. After reading some stuff I want
I am trying to get into android development, after some reading i have settled
I am looking into using Lucene.NET after reading some bad reviews of SQL Server's
I came across couple of questions about OCL expressions. After reading some university slides
I'm trying to understand how ID3 tags work, so, after reading some documentation, I
I want to write a translator between two languages, and after some reading on
After reading all sorts of Stackoverflow postings and various documentation including some on http://code.google.com/p/google-api-java-client/

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.