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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:29:46+00:00 2026-06-10T10:29:46+00:00

i have a problem with my listview. I have a list whit headers. List:

  • 0

i have a problem with my listview. I have a list whit headers.

List: artistas_list
header: artistas_list_s

In the header i wan put a letter ( A , B, C, D, …. )

All works fine except when scroll the list. When scrolling appear a null pointer exception in this line: tt.setText(o.nombre);

It’s strange because at the firs time works fine.

Ok… then y paste the code of the getView

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.artistas_list, null);
        }

        Object content = null;

        Artista o = artistas.get(position);

        try {
            URL url = new URL(o.foto);
            content = url.getContent();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        InputStream is = (InputStream) content;
        Drawable image = Drawable.createFromStream(is, "src");

        TextView tt = (TextView) v.findViewById(R.id.ArtistTopText);
        TextView nid = (TextView) v.findViewById(R.id.txtnid);
        ImageView it = (ImageView) v.findViewById(R.id.imageView1);

        tt.setText(o.nombre);
        nid.setText(o.nid);
        it.setImageDrawable(image);


        String letra= o.nombre.substring(0, 1);


        if(!letra.equals(letraA)){      
            LayoutInflater vo = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vo.inflate(R.layout.artistas_list_s, null);                 
        }
        letraA = letra;
        return v;
    }

Ok, thx for read and try help !!!

LogCat:

 08-28 09:45:24.283: E/AndroidRuntime(512): FATAL EXCEPTION: main
    08-28 09:45:24.283: E/AndroidRuntime(512): java.lang.NullPointerException
    08-28 09:45:24.283: E/AndroidRuntime(512):  at es.okisam.comedy.artistas.ArtistasActivity$ListAdaptor.getView(ArtistasActivity.java:95)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.AbsListView.obtainView(AbsListView.java:1409)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.ListView.fillDown(ListView.java:670)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.ListView.fillGap(ListView.java:641)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3399)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.AbsListView.onTouchEvent(AbsListView.java:2233)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.widget.ListView.onTouchEvent(ListView.java:3446)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.View.dispatchTouchEvent(View.java:3885)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.os.Handler.dispatchMessage(Handler.java:99)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.os.Looper.loop(Looper.java:130)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at java.lang.reflect.Method.invoke(Method.java:507)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-28 09:45:24.283: E/AndroidRuntime(512):  at dalvik.system.NativeStart.main(Native Method)

artistas_list_s

    <?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="wrap_content" >

    <TextView
        android:id="@+id/textSeparator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000"
        android:gravity="center"
        android:text="text"
        android:textColor="#FFFFFFFF"
        android:visibility="visible" />

</LinearLayout>    

artistas_list

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:background="@drawable/fondo"
    android:baselineAligned="false"
    android:gravity="center_vertical|top"
    android:orientation="horizontal"
    android:padding="6dip" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="5dp"
        android:adjustViewBounds="true"
        android:background="@drawable/border_images"
        android:maxHeight="50dp"
        android:maxWidth="50dp"
        android:minHeight="50dp"
        android:minWidth="50dp"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/ArtistTopText"
        android:layout_width="190dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/txtnid"a
        android:layout_toRightOf="@+id/imageView1"
        android:layout_weight="0.02"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtnid"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_weight="1"
        android:src="@drawable/estrella_destacados"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="24dp"
        android:layout_weight="1"
        android:src="@drawable/flecha" />

</RelativeLayout>    

Update with logcat and layouts. Remmember… nullpointer appear when scroll… :S

  • 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-10T10:29:47+00:00Added an answer on June 10, 2026 at 10:29 am

    you are not supposed to do

    content = url.getContent();
    

    in the getview, to begin with, as it is ran in the UI thread.

    Then,

    InputStream is = (InputStream) content;
    

    could be null since it is outside the try {} catch {} block

    finally, given we have no stacktrace or log whatsoever, it may be pretty much anything in your code (views not existing in your layout, object having null fields …)

    Also, your design is weird. If your element does not begin by the same letter as the previous one, you don’t display it, and instead only display its initial?

    Edit

    After looking closely at this, here is what happens in your code:

    1. you inflate artistas_list
    2. you populate it with a thing starting with a
    3. you do the same for a thing starting with b
    4. you inflate artistas_list_s because it does not start with a
    5. you later receive this as a convertView in getView
    6. you look for views that are not present in it (like ArtistTopText)

    See this example http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/ for an example of what you seem to be trying to do.

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

Sidebar

Related Questions

I have a problem with list and listview. I started a project and added
I have a problem saving the list after edit the listview with drag and
I have a problem with adding a listview as a header in my listview
I have a problem my ListActivity . I have this xml: <LinearLayout> <ListView android:id=@android:id/list
I have a problem with listview which list item contain a checkbox. When i
I have a problem with my Android listview. My list uses a custom arrayadapter,
I have an problem to displaying text below listview.when items are more in list
i have my listview activity that works pretty fine but i have an annoying
I have problem adding arraylist to list view, will explain about my problem here..
i have a list view with a BaseAdapter for custom view.. i have problem

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.