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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:58:03+00:00 2026-06-03T19:58:03+00:00

So i have this listview with my custom XML file that i made for

  • 0

So i have this listview with my custom XML file that i made for it.

In the file, there is an image with no source set that has a fixed id.

I want to change this image source to one of my resources in drawable folder.

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView 
 android:id="@+id/listImage"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:contentDescription="protection image"
 android:layout_marginTop="10dp"
/>
<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
>
<TextView android:id="@+id/text1" 
android:textSize="20dp"  
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/text2"
android:textSize="12dp" 
android:layout_marginTop="5dp"
android:layout_width="wrap_content" 
android:layout_height="fill_parent"/>
</LinearLayout>
</LinearLayout>

</LinearLayout>

This is what i have tried so far, and it crashes:

        adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current"},  new int[] {R.id.text1, R.id.text2});
    ImageView img;
    img = (ImageView) findViewById(R.id.listImage);
    Drawable d = getResources().getDrawable(R.drawable.opened);
    img.setImageDrawable(d);
    setListAdapter(adapter);
  • 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-03T19:58:04+00:00Added an answer on June 3, 2026 at 7:58 pm
    ImageView img;
        img = (ImageView) findViewById(R.id.listImage);
    

    This means that you are referring to a object with is present in the layout which you could have used for your Activity’s setContentView().But your ImageView is not present in that layout.

    And here you are trying to refer this with a ListView. So obviously you are getting the null pointer exception.

    You have to make use of a Custom Adapter as well as. Try the one from the below link.

    http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter

    http://www.mkyong.com/android/android-listview-example/

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

Sidebar

Related Questions

I have a Custom ListView created from XML Layout. I want to bind that
I have created a custom listview that is populated using a row.xml file. Each
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
I have a ListView which contains custom rows. This custom row has following UI
I have one custom ListView called AreasListView which I've included in the XML file.
I have a custom listView. The main layout xml is something like this: <?xml
I have a custom ListView in which each row.xml looks like this: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a listview connected to a custom array adapter. This list shows information
I have a nicely working custom CursorAdapter with customized ListView. This view allows the
how to see items that i pick on ListView ? i have this code:

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.