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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:14:08+00:00 2026-06-12T00:14:08+00:00

Hi i am getting a null pointer exception while running my application.. Here is

  • 0

Hi i am getting a null pointer exception while running my application..
Here is my code :

ProductAdapter.java

public class ProductAdapter extends BaseAdapter {

    Context context;
    List<Product> products = new ArrayList<Product>();
    private boolean showCheckbox;


    public ProductAdapter(Context context, List<Product> products,
            boolean showCheckbox) {
        super();
        this.context = context;
        this.products = products;
        this.showCheckbox = showCheckbox;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return products.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return products.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

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

        Product myProduct = products.get(position);

        TextView title = (TextView) convertView.findViewById(R.id.txt_title);
        title.setText(myProduct.getTitle());

        TextView cost = (TextView) convertView.findViewById(R.id.txt_cost);
        cost.setText(myProduct.getCost());

        ImageView image = (ImageView) convertView.findViewById(R.id.imageView1);
        CheckBox selectBox = (CheckBox) convertView.findViewById(R.id.CheckBoxSelect1);

        if(!showCheckbox){
            selectBox.setVisibility(View.GONE);
        }
        else{
            if(myProduct.selected == true)
                selectBox.setChecked(true);
            else
                selectBox.setChecked(false);
        }

        return convertView;
    }
}

Here is my layout xml file
new_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />



    <TextView
        android:id="@+id/txt_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />



    <TextView
        android:id="@+id/txt_cost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />


    <CheckBox
        android:id="@+id/CheckBoxSelect1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

Here i am getting a nullpointer exception please help me out.
Here is my logcat.

09-26 16:37:23.894: D/AndroidRuntime(2611): Shutting down VM
09-26 16:37:23.894: W/dalvikvm(2611): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
09-26 16:37:23.904: E/AndroidRuntime(2611): FATAL EXCEPTION: main
09-26 16:37:23.904: E/AndroidRuntime(2611): java.lang.NullPointerException
09-26 16:37:23.904: E/AndroidRuntime(2611):     at com.shoppingcart.ProductAdapter.getView(ProductAdapter.java:59)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.ListView.makeAndAddView(ListView.java:1772)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.ListView.fillDown(ListView.java:672)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.ListView.fillFromTop(ListView.java:732)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.ListView.layoutChildren(ListView.java:1625)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.AbsListView.onLayout(AbsListView.java:1863)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.View.layout(View.java:11158)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.View.layout(View.java:11158)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.View.layout(View.java:11158)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.View.layout(View.java:11158)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.View.layout(View.java:11158)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1462)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2382)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.os.Looper.loop(Looper.java:137)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at android.app.ActivityThread.main(ActivityThread.java:4340)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at java.lang.reflect.Method.invoke(Method.java:511)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-26 16:37:23.904: E/AndroidRuntime(2611):     at dalvik.system.NativeStart.main(Native Method)

Thank You.
here is my Logcat.

09-26 16:58:35.205: D/AndroidRuntime(2749): Shutting down VM
09-26 16:58:35.205: W/dalvikvm(2749): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
09-26 16:58:35.225: E/AndroidRuntime(2749): FATAL EXCEPTION: main
09-26 16:58:35.225: E/AndroidRuntime(2749): java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageView
09-26 16:58:35.225: E/AndroidRuntime(2749):     at com.shoppingcart.ProductAdapter.getView(ProductAdapter.java:66)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.ListView.makeAndAddView(ListView.java:1772)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.ListView.fillDown(ListView.java:672)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.ListView.fillFromTop(ListView.java:732)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.ListView.layoutChildren(ListView.java:1625)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.AbsListView.onLayout(AbsListView.java:1863)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.View.layout(View.java:11158)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.View.layout(View.java:11158)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.View.layout(View.java:11158)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.View.layout(View.java:11158)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.View.layout(View.java:11158)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewGroup.layout(ViewGroup.java:4197)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1462)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2382)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.os.Looper.loop(Looper.java:137)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at android.app.ActivityThread.main(ActivityThread.java:4340)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at java.lang.reflect.Method.invoke(Method.java:511)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-26 16:58:35.225: E/AndroidRuntime(2749):     at dalvik.system.NativeStart.main(Native Method)
  • 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-12T00:14:10+00:00Added an answer on June 12, 2026 at 12:14 am

    Assign inflated xml file to convertView when its null for the first time.

    if(convertView == null){
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.new_item, null);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting same null pointer exception while running integration test in eclipse .while
Why am i getting this null pointer exception. Here is my code I am
i'm getting a weird null pointer exception in the last line of this code:
I am getting null pointer exception while trying to add anything in my solrQueue.
Iam getting a null pointer exception while sending some string text as an sms
HI i am getting null pointer exception while sending image path to another activity
While running the application I'm getting these errors 10-09 10:20:57.138: ERROR/AndroidRuntime(282): java.lang.RuntimeException: Unable to
I'm getting a Null Pointer Exception while in executing a macro to do some
I am getting NULL pointer exception currently, when I run this thread public void
I am getting a NullPointerException while creating a TreeMap. Here is my code: public

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.