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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:15+00:00 2026-05-29T03:48:15+00:00

Hello stackoverflow community, I’m getting a NPE in my getView method of my custom

  • 0

Hello stackoverflow community,

I’m getting a NPE in my getView method of my custom adapter class which extends BaseAdapter. I hope you can help me.

Here’s my getView method:

@Override
public View getView(int pos, View convertView, ViewGroup viewGroup) {
    if(convertView==null){
        LayoutInflater inflater = (LayoutInflater)context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.row, null);
    }

    TextView datetv = (TextView) convertView.findViewById(R.id.date);
    TextView valuetv = (TextView) convertView.findViewById(R.id.value);
    TextView cattv = (TextView) convertView.findViewById(R.id.cat);

    if(values.get(pos)>VALUE_MIN&&values.get(pos)<VALUE_MAX){
        datetv.setTextColor(context.getResources().getColor(R.color.Good));
        valuetv.setTextColor(context.getResources().getColor(R.color.Good));
        cattv.setTextColor(context.getResources().getColor(R.color.Good));
    }
    else{
        datetv.setTextColor(context.getResources().getColor(R.color.Bad));
        valuetv.setTextColor(context.getResources().getColor(R.color.Bad));
        cattv.setTextColor(context.getResources().getColor(R.color.Bad));
    }

    datetv.setText(dates.get(pos));
    valuetv.setText(Double.toString(values.get(pos)));
    cattv.setText(cats.get(pos));

    LinearLayout l = (LinearLayout) convertView.findViewById(R.id.notelayout);
    l.setFocusableInTouchMode(false);
    l.setFocusable(false);
    l.setOnClickListener(this);
    l.setId(pos);

    return convertView;
}

This is row.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="wrap_content"
  android:orientation="horizontal"

>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="140dip"
    android:layout_height="wrap_content" 
    android:padding="4dip"
    >
<TextView 
android:id="@+id/date" 
android:layout_width="fill_parent" 
android:layout_height="24dip" 
android:textSize="15dip"
android:gravity="left"  android:paddingLeft="6dip" 
android:layout_weight="1" />
<TextView 
android:id="@+id/cat" 
android:layout_width="fill_parent" 
android:layout_height="24dip" 
android:textSize="15dip"
android:gravity="left"  android:paddingLeft="6dip"  
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:gravity="center"
    android:padding="4dip"
    >
    <TextView 
android:id="@+id/value" 
android:layout_width="fill_parent" 
android:layout_height="48dip" 
android:textSize="40dip"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
    android:id="@+id/notelayout"
    android:orientation="vertical"
    android:layout_width="50dip"
    android:layout_height="wrap_content" 
    android:gravity="right"
    android:layout_gravity="center"
    android:padding="4dip"
    >
<ImageView
android:id="@+id/note" 
android:layout_width="wrap_content" 
android:layout_height="48dip" 
android:gravity="center"
android:src="@drawable/papiertje"
android:scaleType="centerInside"/>
</LinearLayout>
</LinearLayout>

And this is the error I’m getting:

01-30 00:34:31.772: ERROR/AndroidRuntime(497): FATAL EXCEPTION: main
01-30 00:34:31.772: ERROR/AndroidRuntime(497): java.lang.NullPointerException
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at com.yellos.android.glucose.ListViewAdapter.getView(ListViewAdapter.java:85)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.AbsListView.obtainView(AbsListView.java:1294)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.ListView.onMeasure(ListView.java:1109)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.View.measure(View.java:8171)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.os.Looper.loop(Looper.java:123)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at java.lang.reflect.Method.invokeNative(Native Method)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at java.lang.reflect.Method.invoke(Method.java:521)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-30 00:34:31.772: ERROR/AndroidRuntime(497):     at dalvik.system.NativeStart.main(Native Method)

Line 85 is l.setFocusableInTouchMode(false);

  • 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-05-29T03:48:15+00:00Added an answer on May 29, 2026 at 3:48 am

    Remove the checking condition of convertView==null in getView()

    Write the Layout inflating code directly without enclosing inside if

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

Sidebar

Related Questions

Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
Hello StackOverflow Community, I hope you guys can help me with this here: On
Hello stackoverflow community ! I am trying to figure out how to architect my
Hello StackOverflow community, The air.swf file referenced here: http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html used to launch AIR applications
Hello StackOverflow community, Is there any way to open a folder in Windows Explorer
Hello StackOverflow community, Is there any way to package the installer for an Adobe
Hello StackOverflow community, I have run into a problem that quite frankly is baffling
Hello World ( stackoverflow ) ! I started up my server, and I'm getting
Hello Stackoverflow community, for a little game I need to display an octagon (
Hello stackoverflow fellow members? Struct Declaration in class A struct PointSprite { GLfloat x;

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.