1
public class ListPage extends ListActivity
{
    TheLists a[] = new TheLists[1];
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.list_page);

        setListAdapter(new MyAdapter());
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {

        class MyAdapter extends ArrayAdapter<TheLists>
        {
            MyAdapter()
            {
                super(ListPage.this, R.layout.list_row, R.id.sname, a);
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent)
            {
                LayoutInflater inflater = getLayoutInflater();
                View row = inflater.inflate(R.layout.list_row,parent,false);

                TextView name,category,id;

                name=(TextView)row.findViewById(R.id.sname);
                category=(TextView)row.findViewById(R.id.scategory);
                id=(TextView)row.findViewById(R.id.sid);
                name.setText(a[0].schemelist[position]);
                category.setText(a[0].categorylist[position]);
                id.setText(a[0].idlist[position]);
                return(row);
            }
        }
    }
}

I'm getting a runtime error which says

05-02 18:56:32.224: E/AndroidRuntime(775): FATAL EXCEPTION: main
05-02 18:56:32.224: E/AndroidRuntime(775): java.lang.NullPointerException
05-02 18:56:32.224: E/AndroidRuntime(775):  at com.example.listinflator_demo.ListPage$MyAdapter.getView(ListPage.java:75)
05-02 18:56:32.224: E/AndroidRuntime(775):  at android.widget.AbsListView.obtainView(AbsListView.java:2159)

what changes are needed ?

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
Abhijeet Limaye
  • 117
  • 3
  • 8

1 Answers1

1

In your constructor, there is something very strange :

you pass a as a parameter to super. But a isn't initialized, never. Where do you get this value from ?

Anyhow, I suggest that you understand better want a null pointer exception means. You will meet this kind of error quite often when programming in java, you would be better understanding how to find and correct them by yourself, it's more interesting than just getting your question answered.

Community
  • 1
  • 1
Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • public class TheLists { public String[] schemelist = {"SCHEME 1", "SCHEME 2", "SCHEME 3", "SCHEME 4", "SCHEME 5", "SCHEME 6", "SCHEME 7", "SCHEME 8", "SCHEME 9", "SCHEME 10"};; public String[] categorylist = {"subsidy", "loan", "scholarship", "subsidy", "loan", "scholarship", "subsidy", "loan", "scholarship", "loan"}; public String[] idlist = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; public String[] nulllist = {}; } 'a' is an object of this "TheLists" class. This maybe a little stupid but there is no 75th line ! – Abhijeet Limaye May 02 '13 at 19:45
  • printout every value mentionned by @luxer. System.out.println( "a is" + a); At the beginning of your method, print variables before using them. Or learn how to debug. For sure there is a line 75 in your class ! Also, please note that an inner class is defined inside a class, not inside one of its methods. – Snicolas May 02 '13 at 20:14