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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:39:21+00:00 2026-06-11T21:39:21+00:00

Hey guys today I started to develop my own little alarmclock app. But now

  • 0

Hey guys

today I started to develop my own little alarmclock app. But now I’ve got a problem, and I’m searching for three hours and couldn’t solve it.

When I try to implement a listview with a custom design for each row, i get a NullPointerException, when I try to set the text from a textview in the layout. The reason for this exception is, that the findViewById-Call returns null and not the TextView I want to have.

On my search I found these two posts, but unfortunately they didn’t help very well…

Post1 – Stackoverflow

Post2 – Stackoverflow

I’m using the same basic structure as in the two post above, but I’m unable to find the mistake…
Here is some code from my app:

The listitem_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="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:padding="6dip" >

 <TextView
    android:name="@+id/toptext"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center_vertical"/>

  <TextView
    android:name="@+id/bottomtext"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center_vertical"/>

 </LinearLayout>

My Adapter:

public class AlarmClockArrayAdapter extends ArrayAdapter<RowItem> {    
    private class ViewHolder {
    TextView headText;
    TextView subText;
   }


public AlarmClockArrayAdapter(Context context, int layoutId, List<RowItem> objects) {
    super(context, layoutId, objects);
    this.mContext    = context;
    this.layoutResourceId = layoutId;
    this.mListItems  = objects;
}


 /**    getView()
 * 
 *  ListView asks the Adapter for a view for each list item element 
 *  Override the getView()-Method to customize the ListView
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    
    ViewHolder holder = null;
    
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if(convertView == null) {
        convertView = inflater.inflate(layoutResourceId, parent, false);
        holder = new ViewHolder();
                    // findViewById(...) returns Null 
        holder.headText = (TextView) convertView.findViewById(R.id.toptext);
        holder.subText  = (TextView) convertView.findViewById(R.id.bottomtext);
        convertView.setTag(holder);     
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }
    
    RowItem rowItem = (RowItem) getItem(position);
    
            // HERES THE NULLPOINTEREXCEPTION
    holder.headText.setText(rowItem.getHeadText());
    holder.subText.setText(rowItem.getSubText());
    
    return convertView;
}

And at least the MainActivity, from where I instantiate the Adapter

public class MainActivity extends Activity {
 public void initList() {

    //Adapter for the listview
    AlarmClockArrayAdapter mAdapter = new AlarmClockArrayAdapter(this, R.layout.listitem_row, this.mListItems);
    
    final ListView mListView = (ListView) findViewById(R.id.listView1);
    mListView.setAdapter(mAdapter);
}

Any help would be great…
Thanks! 😀

  • 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-11T21:39:23+00:00Added an answer on June 11, 2026 at 9:39 pm

    1) check in

    holder.headText.setText(rowItem.getHeadText());
    

    exactly holder.headText return null

    2) check in

    if(convertView == null) {}
    else {
        holder = (ViewHolder) convertView.getTag();
    }
    

    executed first branch

    3) usually I do like this:

    // in constructor
    inflater = LayoutInflater.from(context); // context from Activity
    
    public View getView(int position, @Nullable View convertView, ViewGroup parent) {
      if (convertView == null) {
        convertView = inflater.inflate(R.layout.listitem_row, null);
      }
    
      headText = (TextView) convertView.findViewById(R.id.toptext);
      subText  = (TextView) convertView.findViewById(R.id.bottomtext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
Hey guys I'm getting three things right now that I'm trying to take care
Hey guys I am still sort of a noob but today I finished up
Hey guys thanks for answering I'm really new to Android programming(I started today) and
Hey guys I'm having such a hard time of it today. I have a
Hey guys I wanted to create a JScrollPane but it won't work... and I
Hey guys (and gals) I'm having a problem using Assembly GetExportedTypes() in .NET 4.0.
Hey guys got an issue with Cakephp validation.. I want to know why is
Hey guys i'm making a website but for some reason my div tags are
Hey Guys is it possible to customize an share option? I am exactly searching

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.