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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:52:05+00:00 2026-06-06T15:52:05+00:00

So I have a listview that is displaying correctly. When the item is turned

  • 0

So I have a listview that is displaying correctly. When the item is “turned on” the text is white and when it’s turned off it’s grey. That part all functions great. However when I add the ImageView into the mix I get a null pointer exception. I don’t understand why. I’ve tried using bitmaps as well and get the same problem.

Here is some code:

@Override
public void bindView(View view, Context context, Cursor cursor) {

    TextView rRule = (TextView) view.findViewById(R.id.rule_text);
    TextView rType = (TextView) view.findViewById(R.id.rule_type);
    ImageView iChecked = (ImageView) view.findViewById(R.id.checkBox);



    String ruleName = cursor.getString(1);
    int ruleType = cursor.getInt(2);
    String ruleEnabled = cursor.getString(3);

    switch (ruleType) {
    /*...some irrelevant code */

    }

    if (ruleEnabled.equals("true")) {
        rRule.setTypeface(null, Typeface.BOLD);
        rRule.setTextColor(Color.WHITE);
        iChecked.setVisibility(View.VISIBLE);   //line 271

    } else if (ruleEnabled.equals("false")) {
        rRule.setTypeface(null, Typeface.NORMAL);
        rRule.setTextColor(Color.GRAY);
        iChecked.setVisibility(View.GONE);

    }
    rRule.setText(ruleName);
}

Per request the error log: (Sorry was under the impression null pointers dont say anything helpful..I know the error is the imageview)

06-29 10:29:02.777: E/AndroidRuntime(29516): FATAL EXCEPTION: main
06-29 10:29:02.777: E/AndroidRuntime(29516): java.lang.NullPointerException
06-29 10:29:02.777: E/AndroidRuntime(29516):    at com.company.app.DefaultRulesList$RulesAdapter.bindView(DefaultRulesList.java:271)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at com.company.app.DefaultRulesList$RulesAdapter.newView(DefaultRulesList.java:284)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.CursorAdapter.getView(CursorAdapter.java:246)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.AbsListView.obtainView(AbsListView.java:2033)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.ListView.makeAndAddView(ListView.java:1772)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.ListView.fillDown(ListView.java:672)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.ListView.fillFromTop(ListView.java:732)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.ListView.layoutChildren(ListView.java:1625)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.AbsListView.onLayout(AbsListView.java:1863)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.View.layout(View.java:11278)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.View.layout(View.java:11278)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.View.layout(View.java:11278)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.View.layout(View.java:11278)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.View.layout(View.java:11278)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.os.Looper.loop(Looper.java:137)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at java.lang.reflect.Method.invokeNative(Native Method)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at java.lang.reflect.Method.invoke(Method.java:511)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-29 10:29:02.777: E/AndroidRuntime(29516):    at dalvik.system.NativeStart.main(Native Method)

Code for iChecked (where the id is called)

        <ImageView
android:id="@+id/checkBox"
android:padding="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/checkbox_on_background"/>
  • 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-06T15:52:06+00:00Added an answer on June 6, 2026 at 3:52 pm

    It looks to me like you must be feeding your adapter the wrong layout.

    I can see no other reason for the NPE for the ImageView excpet that it doesn’t exist in the layout where you are looking for it.

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

Sidebar

Related Questions

I have an activity with a listview that is displaying the results of a
I have a ListView that is displaying images downloaded from the internet. My UI
I have a ListView that is displaying data stored in a file, normally, we
Ok I have a ListView that has 2 GridViewColumns one displaying a number and
I have one listview in which i am displaying data that i got, it
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have ListView that uses a GridView to display several columns of data. Two
I have a ListView that shows around 300 items. When something is changed and
I have a listview that highlights a row when you mouseover it with the
I have a listview that contain several EditTexts created dynamically according to the number

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.