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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:12:02+00:00 2026-05-22T16:12:02+00:00

I keep getting a Unable to instantiate activity ComponentInfo… Caused by a NullPointerException at

  • 0

I keep getting a Unable to instantiate activity ComponentInfo... Caused by a NullPointerException at findViewById and i can’t find out why it is throwing it. i have my elements id’s set correctly in my main.xml and i have tried commenting out each line around where it is throwing to see which line is faulty but to get it to run w/o any force closes i have to comment out all the functionality of the program. here is my activity:

package fsg.dev.test.checkboxtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;

public class checkBoxTest extends Activity {
    private CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
    //private SeekBar seekbar = (SeekBar) findViewById(R.id.seekbar);
    private View view = (View) findViewById(R.id.background);

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
            changeColor();
        }
    });
}

private void changeColor(){
    if(checkbox.isChecked()){
        view.setBackgroundColor(R.color.Blue);
        //view.setAlpha(.25);
    }
    else if(!checkbox.isChecked()){
        view.setBackgroundColor(R.color.White);
    }
}

}

and here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="fsg.dev.test.checkboxtest"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:name=".checkBoxTest"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

and finally my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<CheckBox 
    android:text="Background Color" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:checked="false"
    android:id="@+id/checkbox">
</CheckBox>
<SeekBar 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:id="@+id/seekbar" 
    android:layout_margin="10dip" >
</SeekBar>
<View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/White"
    android:id="@+id/background">
</View>
</LinearLayout>

if anyone could help me narrow this down that would be excellent.

  • 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-05-22T16:12:03+00:00Added an answer on May 22, 2026 at 4:12 pm

    You need to use findViewById only after setContentView:

    ....
    public class checkBoxTest extends Activity {
        private CheckBox checkbox;
        private View view;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        checkbox = (CheckBox) findViewById(R.id.checkbox);
        view = (View) findViewById(R.id.background);
        checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                changeColor();
            }
        });
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting a 'System.OutOfMemoryException' thrown at the code below. I can't figure out
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep getting this NPE in my application and I can't seem to get
I am trying to configure an ActiveDirectoryMembershipProvider but I keep getting the message Unable
I'm keep getting this Unable to resolve identifier file message on netbeans. I'm new
I keep getting: Unable to create request (bad url?) error message on a request
I keep getting this when trying to start a new project ERROR: Unable to
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting compiler errors when I try to access flashVars in an AS3
I keep getting asked about AppDomains in interviews, and I know the basics :

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.