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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:48:49+00:00 2026-06-01T12:48:49+00:00

I think my code might be written incorrectly and this is causing my problem.

  • 0

I think my code might be written incorrectly and this is causing my problem. basically I’m trying to create multiple ‘program’ buttons (these buttons are made up of Relative view, linearview, 2 text views, 2 buttons). You can see the code below. I created this structure in an XML and I am inflating that XML when I want a new program added to the app. I then add ID’s based on the Database unique ID and assign it to all the created views of this button.

it seems to work fine, for clicking on buttons etc.. problem is when I’m trying to destroy a button my app keeps crashing. now I’m starting to wonder if there is somehting fundamentally incorrect with the method I’ve chosen.

   public void buildprogramholders(String rowID, String title_text, String description_text) {

        int dbRowID = Integer.parseInt(rowID);

        totalTid++;

        LinearLayout ll = (LinearLayout)findViewById(R.id.traininglist);

        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.trainingprogram, ll);

        tp_container = new RelativeLayout(this);
        tp_container = (RelativeLayout) findViewById(R.id.tp_container);
        tp_container.setId(dbRowID);

        tp_icon = new ImageView(this);
        tp_icon = (ImageView) findViewById(R.id.tp_icon);
        tp_icon.setId(dbRowID);

        tp_textholder = new LinearLayout(this);
        tp_textholder = (LinearLayout)findViewById(R.id.tp_textholder);
        tp_textholder.setId(dbRowID);

        //tp_title = new TextView(this);
        tp_title = (TextView)findViewById(R.id.tp_title);
        tp_title.setId(dbRowID);
        tp_title.setText(title_text);

        tp_description = new TextView(this);
        tp_description = (TextView)findViewById(R.id.tp_description);
        tp_description.setId(dbRowID);
        tp_description.setText(description_text);

        tp_button = new Button(this);
        tp_button = (Button)findViewById(R.id.tp_button);
        tp_button.setId(dbRowID);
        tp_button.setTag(3);
        tp_button.setOnClickListener(this);

        tp_delete_button = new Button(this);
        tp_delete_button = (Button)findViewById(R.id.tp_delete_button);
        tp_delete_button.setId(dbRowID);
        tp_delete_button.setTag(6);
        tp_delete_button.setOnClickListener(this);


    }

Then in the OnClick I try to remove the program. I tried commenting out the whole drop_tp_xx.setVisibitly(View.gone) area and the program works. if I reinstate any single line from there my program become unrelaiable. sometimes I can delete one or two, then it crashes?

    public void onClick(View v) {
int rowId = v.getId();
                    RelativeLayout  drop_tp_container   = (RelativeLayout) tp_container.findViewById(rowId);            
                    ImageView       drop_tp_icon        = (ImageView) tp_icon.findViewById(rowId);
                    LinearLayout    drop_tp_textholder  = (LinearLayout) tp_textholder.findViewById(rowId);
                    TextView        drop_tp_title       = (TextView) tp_title.findViewById(rowId);
                    TextView        drop_tp_description = (TextView) tp_description.findViewById(rowId);
                    Button          drop_tp_button      = (Button) tp_button.findViewById(rowId);
                    Button          drop_tp_delete_button = (Button) tp_delete_button.findViewById(rowId);



                    drop_tp_container.removeAllViews();
                    drop_tp_delete_button.setClickable(false);
                    drop_tp_button.setClickable(false);     
                    drop_tp_title.setVisibility(View.GONE);
                    drop_tp_description.setVisibility(View.GONE);
                    drop_tp_delete_button.setVisibility(View.GONE);
                    drop_tp_textholder.setVisibility(View.GONE);
                    drop_tp_icon.setVisibility(View.GONE);
                    drop_tp_button.setVisibility(View.GONE);
                    drop_tp_container.setVisibility(View.GONE);

    }

Error dump text

04-04 14:20:06.145: E/AndroidRuntime(17242): java.lang.NullPointerException
04-04 14:20:06.145: E/AndroidRuntime(17242):    at com.mediabarltd.digittrainer.HomePage.onClick(HomePage.java:153)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.view.View.performClick(View.java:2538)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.view.View$PerformClick.run(View.java:9152)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.os.Handler.handleCallback(Handler.java:587)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.os.Looper.loop(Looper.java:130)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at android.app.ActivityThread.main(ActivityThread.java:3691)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at java.lang.reflect.Method.invoke(Method.java:507)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-04 14:20:06.145: E/AndroidRuntime(17242):    at dalvik.system.NativeStart.main(Native Method)

thanks for looking.

  • 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-01T12:48:50+00:00Added an answer on June 1, 2026 at 12:48 pm

    You are trying to access a reference that does not exist on line 153 in your onClick method.

    You dont give line numbers so I cannot tell what line that is in your code but try setting a breakpoint on that line and see why the reference is null.

    Update:

    You are using findViewById incorrectly.

    you should use rootlayout.findViewById(ID) where rootlayout is the parent layout. You are currently trying to access the button from within itself which is where your null reference is coming from.

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

Sidebar

Related Questions

http://projecteuler.net/problem=20 I've written code to figure out this problem, however, it seems to be
I don't think my code's the problem because it's working on my local server
I think the following code can be used to create manipulators. #include<iostream> ostream &
Best explained with code I think, this is just a simple example: public class
How do you think about data access code like this: public void AddCusotmer(Cusotmer customer)
I have written this piece of code public class Test{ public static void main(String[]
This extremely cool article written in the winter of 2007 shows me this code:
I've written some code (static library) in c++, with (i think so, C compatiblity
The following C++ code i think is correct, but produce some warnings when compiled
The code below shows me (I think) that the for each loop is about

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.