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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:31:39+00:00 2026-05-23T05:31:39+00:00

i have a list view in my app with image buttons and i write

  • 0

i have a list view in my app with image buttons and i write action for each image button.
but i get null pointer exception when touch the image buttons. i do not know the reason. please help me.

my code:

public class InventoryListActivity extends ListActivity {

private InventoryAdapter adapter;
private InventoryObserver inventoryObserver;
ListView listview;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.inventory_list);

    if(!IAPManager.isBillingSupported())
        showDialog(1);

   listview = (ListView)findViewById(R.id.listExample); 

   adapter = new InventoryAdapter(this);  // here i call InventoryAdapter class for list view the items.
   setListAdapter(adapter);

   inventoryObserver = new InventoryObserver();
   IAPManager.shared().getInventory().addObserver(inventoryObserver);

   listview.setOnItemClickListener(new OnItemClickListener(){
       public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
             switch(view.getId()){
                 case R.id.imageButton1:
                     Log.e("Buy","buy position"+position);
                     break;
                 case R.id.imageButton2:
                     Log.e("play","play position"+position);
                     break;
                 case R.id.imageButton3:
                     Log.e("detail","detail  position"+position);
                     break;  
              }   
       }     
   });


}

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    Log.e("position",""+pos);
}

}

in InventoryAdapter class:

    public class InventoryAdapter extends BaseAdapter implements Observer{

public InventoryAdapter(Context ctx) {     
    context = ctx;
    inventory = IAPManager.shared().getInventory();
    inventory.addObserver(this);
    inventory.load();
}
.......
@Override
public int getCount() {
    return inventory.size(Inventory.FilterType.ALL);
}

@Override
public Object getItem(int position) {
    return inventory.getProducts(Inventory.FilterType.ALL).get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Product product = (Product) getItem(position);

    View view;

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

    else {
        view = convertView;
    }
    ..........
    return view;
}

}

in inventory_list.xml:

 <ListView android:id="@+id/listExample"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>

in Inventry_list_item.xml:

        ...... 
       <ImageButton android:background="@drawable/play_btn"  android:focusable="false" android:onClick="onItemClick"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton2" android:layout_weight="0.5" />
        ......

Log cat:

    ERROR/AndroidRuntime(2038): Caused by: java.lang.NullPointerException
     ERROR/AndroidRuntime(2038):     at com.google.iap.BillingService.handleCommand(Unknown Source)
    ERROR/AndroidRuntime(2038):     at com.google.iap.BillingService.onStart(Unknown Source)
    ERROR/AndroidRuntime(2038):     at android.app.Service.onStartCommand(Service.java:306)
    ERROR/AndroidRuntime(2038):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2873)
  • 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-23T05:31:40+00:00Added an answer on May 23, 2026 at 5:31 am

    you have put the differant xml in the InventoryListActivity class rather the Inventry_list_item.xml dat meas i need to inflate this view component in this class then after u can user those view in your class .

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

Sidebar

Related Questions

in my app i have a list view. Each list consists of a image,
I have an android app, where in a list view for each element in
I have an Android app with a ListActivity in the main view. The list
in my app i use list view. in the list view i have three
i am using list view to get messages with image. it is working fine,when
I have a navigation based app. Press a button on main view, then I
I have an app using a ListView as a main screen. Each row displays
I have a list view control which at the moment only allows one item
I have a list view that is periodically updated (every 60 seconds). It was
I have a list view filled with data. I set up a context menu

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.