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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:08:28+00:00 2026-06-04T18:08:28+00:00

Help! I am getting the findViewById null return value problem. I did tons of

  • 0

Help! I am getting the findViewById null return value problem. I did tons of research and already clearned project, put setContentView ahead, but it still fail! The xml layout works fine because if i set my custom view’s back ground to blue, the view will have blue color as expected when running the app. But i just cant use findViewById

layout xml:

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

<shaotian.android.blackboard.BBView
    android:id="@+id/bBView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</FrameLayout>

custom view class, its parent class extends android’s view class already:

package shaotian.android.blackboard;
import java.util.Observable;
import java.util.Observer;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class BBView extends shaotian.android.blackboard.View {


public BBView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    TextView txt=new TextView(context);
    this.setBackgroundColor(Color.BLUE);

}
public BBView(Context context, AttributeSet attr)
{super(context);
this.setBackgroundColor(Color.BLUE);
}

public BBView(Context context,AttributeSet attr,int sty)
{
    super(context,attr,sty);
    this.setBackgroundColor(Color.BLUE);
}


@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
}

public void update(Observable arg0, Object arg1) {
    // TODO Auto-generated method stub

}

}

Activity class:

package shaotian.android.blackboard;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class BlackBoardActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    BBView view=(BBView)findViewById(R.id.bBView1);

}
}
  • 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-04T18:08:29+00:00Added an answer on June 4, 2026 at 6:08 pm

    You are calling the wrong super constructor here:

    public BBView(Context context, AttributeSet attr)
    {
       super(context);
       this.setBackgroundColor(Color.BLUE);
    }
    

    Should be:

    public BBView(Context context, AttributeSet attr)
    {
       super(context, attr);
       this.setBackgroundColor(Color.BLUE);
    }
    

    Also, in the pasted code for the activity I don’t see the import for R, make sure you import your project’s R file, and not com.android.R by mistake.

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

Sidebar

Related Questions

I need help finding why I'm getting a null pointer exception. I've tried going
I need some help getting data from several tables. This is the tables I
I recently had help getting the correct Date format on my jQuery / tablesorter
I need a little help getting a tar file to download from a website.
I need help getting git extensions to run with msysgit. I have had bad
I need help getting a Grease Monkey with JQuery Script to run on a
I need help getting two pieces of data, and comparing them. What I am
I need help getting my java program ready for release. I have a program
I know there has to be a way: I need help getting any hot
I was getting help related to a previous question but then told to ask

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.