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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:25:17+00:00 2026-06-05T19:25:17+00:00

I would like my screen to have a listview with a header. In my

  • 0

I would like my screen to have a listview with a header.

In my XML file, I have a listview and just above it there is an imageview, which is being used as the header.

When I run this I get an error. I have gone through dozens of tutorials and I can’t see what I am doing wrong. I have searched Stackoverflow and all tried the solutions but had no joy. Can anybody help me please?

Note: I am using Actionbarsherlock, so my class extends SherlockListActivity. I have tried this with ListActivity and get the same problem. I have also tried running without instantiating the image to see if the listview loads itself, and still I get the same error.

Please see my XML and code below:

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" >

<ImageView
    android:id="@+id/headerimage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/header" >
</ImageView>

<ListView
    android:id="@+id/mylist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

My code:

public class MainActivity extends SherlockListActivity {

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

    ImageView header = (ImageView) findViewById(R.id.headerimage);
    ListView listView = (ListView) findViewById(R.id.mylist);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
    "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
    "Linux", "OS/2" };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, android.R.id.text1, values);

        listView.addHeaderView(header);
    listView.setAdapter(adapter);




}

Error log

E/AndroidRuntime(10642): FATAL EXCEPTION: main
E/AndroidRuntime(10642): java.lang.RuntimeException: Unable to start activity ComponentInfo{ttj.android.t3w/ttj.android.t3w.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(10642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
E/AndroidRuntime(10642):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
E/AndroidRuntime(10642):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
E/AndroidRuntime(10642):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
E/AndroidRuntime(10642):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10642):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(10642):    at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(10642):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(10642):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(10642):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/AndroidRuntime(10642):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime(10642):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(10642): Caused by: java.lang.NullPointerException
E/AndroidRuntime(10642):    at ttj.android.t3w.MainActivity.onCreate(MainActivity.java:40)
E/AndroidRuntime(10642):    at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(10642):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(10642):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
E/AndroidRuntime(10642):    ... 11 more
  • 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-05T19:25:19+00:00Added an answer on June 5, 2026 at 7:25 pm

    FIXED.

    The activity should NOT extend ListActivity. I changed it to Activity and the problem has gone.

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

Sidebar

Related Questions

I have a video view that is full screen and would like to trigger
I would like to develop a selection-tool for Screen which ignores the leading spaces
I have five activities/screens that I would like to be able to swipe between,
I would like to know the screen resolution of a visitor visiting my page
I would like to add details to the incoming call screen on android. lets
Would like to make anapplication in Java that will not automatically parse parameters used
I have implemented a custom list view which looks like the twitter timeline. adapter
I have a listview on the bottom part of the screen and a 4
I have a LinearLayout that I would like to change the background color of
I have an activity in Android which uses a ListView. When I click on

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.