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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:18:54+00:00 2026-06-08T20:18:54+00:00

I’ve created a Custom Component in layout/XML which has 2 TextViews and 2 Buttons.

  • 0

I’ve created a Custom Component in layout/XML which has 2 TextViews and 2 Buttons.
In its supporting class I simply have buttons increment and decrement the value of one of the TextViews

public class NumberStepper extends LinearLayout implements View.OnClickListener {

//Define the elements (Children) of the compound view
public TextView tvStepperName, tvStepperValue;
public Button btnIncrement, btnDecrement;

private int statValue;
public NumberStepper(Context context, AttributeSet attrs) {
    super(context, attrs);
    //tvStepperName.setText(name);
    statValue = 0;

    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.numberstepper, this);
    loadComponents();

    }
private void loadComponents(){
    tvStepperName = (TextView) findViewById(R.id.tvStepperName);
    tvStepperValue = (TextView) findViewById(R.id.tvStepperValue);
    btnIncrement = (Button) findViewById(R.id.btnIncrement);
    btnDecrement = (Button) findViewById(R.id.btnDecrement);

    btnIncrement.setOnClickListener(this);
    btnDecrement.setOnClickListener(this);

    tvStepperValue.setText("" + statValue);

}

public void setLabel(String str){
    tvStepperName.setText(str);
}
public void onClick(View v) {
    switch(v.getId()){
    case R.id.btnIncrement:
            statValue++;
            tvStepperValue.setText("" + statValue);
            tvStepperName.setText("HELLO");
        break;
    case R.id.btnDecrement:
        if(statValue > 0){
            statValue--;
        }
        tvStepperValue.setText("" + statValue);
        break;
    }

}

}

Next I created another XML layout that has 5 or 6 of these compound components

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.nsholmes.bballStats.componets.NumberStepper
    android:id="@+id/ccOne"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></com.nsholmes.bballStats.componets.NumberStepper>
<com.nsholmes.bballStats.componets.NumberStepper
    android:id="@+id/ccTwo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></com.nsholmes.bballStats.componets.NumberStepper>

In this layout’s support class (which extends Activity) I set the compound component variables, setContentView(),and I attempt the following:

ccOne = (NumberStepper)findViewById(R.id.ccOne);
    ccOne.setLabel("Label Name");

I get an error stating – Unable to start activity ComponentInfo). I only get this error when I call setLabel().

07-31 17:54:25.657: E/AndroidRuntime(11454): FATAL EXCEPTION: main
07-31 17:54:25.657: E/AndroidRuntime(11454): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsholmes.bballStats/com.nsholmes.bballStats.games.Game}: java.lang.NullPointerException
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.os.Looper.loop(Looper.java:137)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread.main(ActivityThread.java:4514)
07-31 17:54:25.657: E/AndroidRuntime(11454): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 17:54:25.657: E/AndroidRuntime(11454): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 17:54:25.657: E/AndroidRuntime(11454): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-31 17:54:25.657: E/AndroidRuntime(11454): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-31 17:54:25.657: E/AndroidRuntime(11454): at dalvik.system.NativeStart.main(Native Method)
07-31 17:54:25.657: E/AndroidRuntime(11454): Caused by: java.lang.NullPointerException
07-31 17:54:25.657: E/AndroidRuntime(11454): at com.nsholmes.bballStats.games.Game.loadComponents(Game.java:34)
07-31 17:54:25.657: E/AndroidRuntime(11454): at com.nsholmes.bballStats.games.Game.onCreate(Game.java:27)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.Activity.performCreate(Activity.java:4465)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
07-31 17:54:25.657: E/AndroidRuntime(11454): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
07-31 17:54:25.657: E/AndroidRuntime(11454): … 11 more

Any help would be appreciated, Thanks
THis is the full layout for the numberstepper

<TextView
    android:id="@+id/tvStepperName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="FreeThrow"
    android:layout_weight="10" />

<Button
    android:id="@+id/btnIncrement"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="30"
    android:text="@string/plusSign" />"

<Button
    android:id="@+id/btnDecrement"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="30"
    android:text="@string/minusSign" />

<TextView
    android:id="@+id/tvStepperValue"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="2"
    android:layout_weight="30" />


</LinearLayout>
  • 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-08T20:18:55+00:00Added an answer on June 8, 2026 at 8:18 pm

    Problem might be that with the way you are trying to find the view. As I understand it findViewById(..) works based off of setContentView(..) and since there is no content view set in your class the view returned is null.

    Maybe you can try to find the TextView from the inflated view.

    .....
    private int statValue;
    private View mView;
    
    public NumberStepper(Context context, AttributeSet attrs) {
        super(context, attrs);
        //tvStepperName.setText(name);
        statValue = 0;
    
        LayoutInflater inflater = LayoutInflater.from(context);
        mView = inflater.inflate(R.layout.numberstepper, this);
        loadComponents();
    
    }
    
    private void loadComponents(){
        tvStepperName = (TextView) mView.findViewById(R.id.tvStepperName);
        tvStepperValue = (TextView) mView.findViewById(R.id.tvStepperValue);
        btnIncrement = (Button) mView.findViewById(R.id.btnIncrement);
        btnDecrement = (Button) mView.findViewById(R.id.btnDecrement);
    .....
    }
    .....
    .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.