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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:52:57+00:00 2026-06-07T21:52:57+00:00

I got an exception ( null pointer ) when I call the method addView()

  • 0

I got an exception (null pointer) when I call the method addView() on my relative layout to add the textView

public class FormAddNewTaskActivity extends Activity {

    private final String TAG = FormAddNewTaskActivity.class.getCanonicalName();

    private TaskLiteApplication taskLiteApplication;

    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.form_add_task);

        RelativeLayout rl = (RelativeLayout) findViewById(R.layout.form_add_task);
        TextView tv = new TextView(taskLiteApplication);
        tv.setText("blah blah");
        tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        rl.addView(tv); //null pointer exeption there

        //set application context
        taskLiteApplication = ((TaskLiteApplication)getApplicationContext());

        //Spinner set list user
        Spinner s = (Spinner) this.findViewById(R.id.spinnerUser);

        //set list user
        ArrayList<User> listUser = taskLiteApplication.getCtrlUser().getListUserFromDataBase();

        //adapter user
        UserSpinnerAdapter userSpinnerAdapter = new UserSpinnerAdapter(listUser , getApplicationContext());

        //set adapter on the spinner
        s.setAdapter(userSpinnerAdapter);



        //set listener on add button task
        ImageButton imageButtonAdd = (ImageButton) findViewById(R.id.imageButtonAdd);
        imageButtonAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "add form new subtask");
            }
        });


    }

}

My XML:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <EditText
            android:id="@+id/editTextGroupTaskName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_task_name"
            >

            <requestFocus />
        </EditText>

         <Spinner
            android:id="@+id/spinnerUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textViewDateDue"
            android:layout_below="@+id/editTextGroupTaskName" />      

        <TextView
            android:id="@+id/textViewDateDue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/spinnerUser"
            android:text="@string/date_due"
            android:textColor="#000"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <DatePicker
            android:id="@+id/datePickerDateDue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/textViewDateDue" />

        <TextView 
            android:id="@+id/textViewSubTask"
            android:layout_below="@id/datePickerDateDue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sub_task"
            android:textColor="#000"
            android:paddingTop="11dp"
            android:paddingBottom="11dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            />

        <ImageButton
            android:id="@+id/imageButtonAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/datePickerDateDue"
            android:src="@drawable/add" />

    </RelativeLayout>


</ScrollView>

Log Cat :

 07-17 14:07:40.696: D/AndroidRuntime(338): Shutting down VM
...
07-17 14:07:40.707: E/AndroidRuntime(338): Caused by: java.lang.NullPointerException
07-17 14:07:40.707: E/AndroidRuntime(338):  at android.view.View.<init>(View.java:1823)
07-17 14:07:40.707: E/AndroidRuntime(338):  at android.widget.TextView.<init>(TextView.java:326)
07-17 14:07:40.707: E/AndroidRuntime(338):  at android.widget.TextView.<init>(TextView.java:320)
07-17 14:07:40.707: E/AndroidRuntime(338):  at android.widget.TextView.<init>(TextView.java:315)
07-17 14:07:40.707: E/AndroidRuntime(338):  at activity.FormAddNewTaskActivity.onCreate(FormAddNewTaskActivity.java:38)
07-17 14:07:40.707: E/AndroidRuntime(338):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  • 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-07T21:52:59+00:00Added an answer on June 7, 2026 at 9:52 pm

    RelativeLayout rl = (RelativeLayout) findViewById(R.layout.form_add_task);

    You are sending a layout tag to a View finder. Add this to your XML:

    <RelativeLayout
            android:id="@+id/form_add_task"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
    

    and call:

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.form_add_task);

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

Sidebar

Related Questions

ive got this exception. My Object looks like this: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ObjectDTO
I was examining the use of ServletContext when i got the null pointer exception.
I got a null pointer exception fault in java servlet. Could someone tell me
I've got exception about convert NULL to Int32. I've got a table from database
I got some error when i try to call a public variable in my
I've been at this one for a bit now. I've got a null pointer
i got a pointer to char in my class that would later be used
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
I am very surprised by the strange exception, that I got. class Threads {
I am trying to learn how to location services and I got Null Pointer

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.