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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:48+00:00 2026-05-24T03:01:48+00:00

i have a button called ‘edit’ and below the button i have a list

  • 0

i have a button called ‘edit’ and below the button i have a list view. By default in the list i hide the minus image button and delete image button. if i click edit button minus image button to be shown for all list items and if i touch a minus image button of a item the corresponding list item’s delete button to be shown. and if i touch the delete button the corresponding row to be deleted. i did the following if click edit button i get null pointer exception.

public class Favorite extends ListActivity implements OnClickListener{


ImageButton delete,del1,del2,editbutton;
private Context context;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favorite_list_view);

    editbutton = (ImageButton)findViewById(R.id.editbutton);

    del1 = (ImageButton)findViewById(R.id.delete1);


    editbutton.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View view) 
        {
           del1.setVisibility(View.VISIBLE);  // line no 69 . i get null pointer exception here. 
        }

    });        
    String favorite_list[];
    int count=0;

    //      database coding ....
    ..........              

   setListAdapter(new ArrayAdapter<String>(this,R.layout.favorite_row_view, R.id.text1, favorite_list));



} 
protected void onListItemClick(ListView l, View convertView, int position, long id) {
    super.onListItemClick(l, convertView, position, id);

    View view;

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater)
        context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.favorite_row_view, null);

        del1 = (ImageButton)view.findViewById(R.id.delete1);
        delete = (ImageButton)view.findViewById(R.id.delete2);

        del1.setOnClickListener(this);
        delete.setOnClickListener(this);

    }

    else {
        view = convertView;
    }

    del1 = (ImageButton)view.findViewById(R.id.delete1);
    delete = (ImageButton)view.findViewById(R.id.delete2);

    del1.setTag(position);
    delete.setTag(position);



    Object o = this.getListAdapter().getItem(position);
    String pen = o.toString();
    Toast.makeText(this, ""+position + "-" +"fid - "+""+favoritelist.get(position)+ pen, Toast.LENGTH_SHORT).show();
    Bundle bundle = new Bundle();
    ..........
    Intent myIntent = new Intent(convertView.getContext(), favorite_swipe.class);
    myIntent.putExtras(bundle);
    startActivityForResult(myIntent, 0);

}
@Override
public void onClick(View v) {
    Integer position = (Integer) v.getTag();
    switch(v.getId()){
    case R.id.delete1:
        Toast.makeText(this,position+"- delete1", Toast.LENGTH_SHORT).show();
        del1.setVisibility(View.VISIBLE);
        delete.setVisibility(View.VISIBLE);
    break;  
    case R.id.delete2:
        Toast.makeText(this,position+"-delete2", Toast.LENGTH_SHORT).show();
        del1.setVisibility(View.VISIBLE);
        delete.setVisibility(View.VISIBLE);
    break;          
    }

}

}

log cat:

  07-28 19:38:21.019: ERROR/AndroidRuntime(9672): FATAL EXCEPTION: main
  07-28 19:38:21.019: ERROR/AndroidRuntime(9672): java.lang.NullPointerException
  07-28 19:38:21.019: ERROR/AndroidRuntime(9672):     at com.sql.test.Favorite$3.onClick(Favorite.java:69)
  07-28 19:38:21.019: ERROR/AndroidRuntime(9672):     at android.view.View.performClick(View.java:2408)
  07-28 19:38:21.019: ERROR/AndroidRuntime(9672):     at android.view.View$PerformClick.run(View.java:8816)
  • 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-24T03:01:49+00:00Added an answer on May 24, 2026 at 3:01 am

    here is the final one..

    ListView list = favorite_list_view.findViewById(R.id.lisViewId);
    Button b= list.findViewById(R.id.buttonId);
    

    and etc.. this has to work if you are giving proper IDs to listView and Button

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

Sidebar

Related Questions

I have a button called WatchMode. When you click this button, it will close
i have a button called ac and when i click on it, i want
I have a button in html called btnS: <button type=submit id=btnS class=hide value=button>Send</button> That
I have a view controller called searchUpdateController , it has a button to push
I have an ASP.NET MVC Page with a button called Start Live Meeting. When
Assume we have a single Windows form with a button called SimpleButton1. The following
I have a WPF window, which contains a button called Cancel. Under ordinary circumstances
I have a UserControl called CustomerFinder for searhing customers. And there is "ADD" button
I have a form with a submit button. I have called a function on
I have one issue with UInavigationcontroller In my firstview i have button.If i click

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.