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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:10:29+00:00 2026-05-13T07:10:29+00:00

Hey guys i have a ListActivity… a very simple at that… and it keeps

  • 0

Hey guys i have a ListActivity… a very simple at that… and it keeps throwing NullPointer Exception though i have done it exactly as the Sample List7 except that i have used the Layout inflater… below is the code… Can u plz comment the error i have done here??

import java.util.Vector;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

public class CustomList extends ListActivity implements OnItemSelectedListener{
    Vector<String> VTitle;
    Vector<String> VDescription;
    TextView display;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VTitle.addElement("First Title");
        VTitle.addElement("Second Title");
        VTitle.addElement("Third Title");
        VTitle.addElement("Fourth Title");
        VDescription.addElement("1 Description");
        VDescription.addElement("2 Description");
        VDescription.addElement("3 Description");
        VDescription.addElement("4 Description");
        display = (TextView)findViewById(R.id.display);
        setListAdapter(new CustomAdapter(this));
    }     
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        display.setText(VTitle.elementAt(position));
    }

    class CustomAdapter extends BaseAdapter {
        protected Activity mContext;

        public CustomAdapter(Activity context) {
            mContext = context;
            // TODO Auto-generated constructor stub
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return VTitle.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View row = convertView;
            if(row==null) {
                LayoutInflater inflater = mContext.getLayoutInflater();
                row = inflater.inflate(R.layout.row,null);
            }
            TextView title = (TextView)row.findViewById(R.id.title);
            title.setText(VTitle.elementAt(position));
            TextView description = (TextView)row.findViewById(R.id.description);
            description.setText(VDescription.elementAt(position));
            ImageView image = (ImageView)row.findViewById(R.id.image);
            switch(position){
                case 0:
                    image.setImageResource(R.drawable.check);
                    break;
                case 1:
                    image.setImageResource(R.drawable.dos);
                    break;
                case 2:
                    image.setImageResource(R.drawable.smily);
                    break;
                case 3:
                    image.setImageResource(R.drawable.wrong);
                    break;
            }
            return(row);
        }
    }

    @Override
    public void onItemSelected(AdapterView parent, View v, int position, long id) {
        // TODO Auto-generated method stub
        display.setText(VTitle.elementAt(position));
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    }
}

And the xmls are like this….

“main.xml”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id = "@+id/display"
        android:text="something"
        />
    <ListView 
         android:id="@android:id/list" 
         android:layout_width="fill_parent" 
         android:drawSelectorOnTop="false" 
        android:layout_height="0px">
    </ListView>
</LinearLayout>

“row.xml”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView 
        android:id="@+id/image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">    
    </ImageView>
    <TextView 
        android:text="Title" 
        android:id="@+id/title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
    <TextView 
        android:text="description" 
        android:id="@+id/description" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
</LinearLayout>
  • 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-13T07:10:30+00:00Added an answer on May 13, 2026 at 7:10 am

    VTitle and VDescription aren’t initialized

    Before accessing one of these attributes, you should :

    VTitle = new Vector<String>();
    VDescription = new Vector<String>();
    

    Moreover in java, the first letter of an attribute name should be lowercase, and in android this first letter should be an m, to denote a member field.

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

Sidebar

Related Questions

hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Hey right now I'm using jQuery and I have some global variables to hold
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, I've been developing an application in the windows console with Java, and want
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my

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.