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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:44:45+00:00 2026-06-13T03:44:45+00:00

Hi I have a layout in which there are 4 Button , the Button

  • 0

Hi I have a layout in which there are 4 Button, the Button are placed in a separate LinearLayout. The LinearLayout have id’s assigned to them. Now in my activity which holds this layout, I am creating LinearLayout variables and assigning id’s to them.

Now when I try to run the code, the following error is displayed .![enter image description here][1]

10-19 12:36:43.899: E/AndroidRuntime(21774): FATAL EXCEPTION: main
10-19 12:36:43.899: E/AndroidRuntime(21774): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.code.accountmanager/com.code.accountmanager.AccountManagerActivity}: java.lang.NullPointerException

also

10-19 12:36:43.899: E/AndroidRuntime(21774): Caused by: java.lang.NullPointerException
10-19 12:36:43.899: E/AndroidRuntime(21774):    at android.app.Activity.findViewById(Activity.java:1825)
10-19 12:36:43.899: E/AndroidRuntime(21774):    at com.code.accountmanager.AccountManagerActivity.<init>(AccountManagerActivity.java:22)

Also the line in which error is displayed is as:

LinearLayout l4 = (LinearLayout) findViewById(R.id.anim_recent_transaction);
LinearLayout l3 = (LinearLayout) findViewById(R.id.anim_view_account);
LinearLayout l2 = (LinearLayout) findViewById(R.id.anim_add_transaction);
LinearLayout l1 = (LinearLayout) findViewById(R.id.anim_add_account);

here is the xml code

    <LinearLayout
        android:id="@+id/buttonHolder"
        android:layout_width="120dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/anim_add_account"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <ImageButton
                android:id="@+id/addAccount"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:background="@drawable/addaccount_new"
                android:gravity="center" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="10dp" />

        <LinearLayout
            android:id="@+id/anim_add_transaction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <ImageButton
                android:id="@+id/addTransaction"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:background="@drawable/addtransaction_new"
                android:gravity="center" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="10dp" />

        <LinearLayout
            android:id="@+id/anim_view_account"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <ImageButton
                android:id="@+id/viewAccount"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:background="@drawable/viewaccounts_new"
                android:gravity="center" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="10dp" />

        <LinearLayout
            android:id="@+id/anim_recent_transaction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <ImageButton
                android:id="@+id/recentTransaction"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:background="@drawable/viewtransaction_new"
                android:gravity="center" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Please tell me what could I do to remove the error.

  • 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-13T03:44:47+00:00Added an answer on June 13, 2026 at 3:44 am

    You should add setContentView(R.layout.yourLayoutXML) before using findViewById.
    I think that might be your problem

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

Sidebar

Related Questions

I have a layout which looks like this: <LinearLayout> <ImageView> android:width=wrap_content android:height:wrap_content ... </ImageView>
I have created an activity in which there is four button in center .
I have this textbox in the other activity and a button which leads to
I have a LinearLayout, which only contains one button. I want this button to
I have a CustomButton class (extends LinearLayout ) where I inflate a layout which
I have a layout like this in which I want to display a label
I have the following code in my app. There is a login button which
I have an xml file right now which has a TableLayout within a LinearLayout.
I have a layout in which the first button keeps grabbing focus as soon
I have made an android application in which there is a text and button

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.