0

I am getting null pointer exception in below code as I mentioned in comment. I am confused why its so and need help. Does the list of people is null ? I am trying to display list of people and someone please explain how this execute() works in active android.

Thanks.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_all);

        mListAll = (ListView) findViewById(R.id.list_all);
        mTextEmptyList = (TextView) findViewById(R.id.list_empty_message);
        mInflater = LayoutInflater.from(this);
        initListWithData(); //null pointer
    }
private void initListWithData() {
    ArrayList<Person> people = new Select()
            .all()
            .from(Person.class)
            .execute();  //null pointer
    mAdapter = new SunilListAdapter(this);
    mAdapter.setData(people);
    mListAll.setAdapter(mAdapter);
    mListAll.setEmptyView(mTextEmptyList);
    mListAll.setOnItemClickListener(this);

}

person class

 package com.example.model;

    import java.io.Serializable;
    import com.activeandroid.Model;
    import com.activeandroid.annotation.Column;
    import com.activeandroid.annotation.Table;

    //Notice how we specified the name of the table below
    @Table(name = "Person")
    public class Person extends Model implements Serializable{

        // Notice how we specified the name of our column here
        @Column(name = "personName")
        public String personName;

        // Notice how we specified the name of our column here
        @Column(name = "personAge")
        public int personAge;

        @Column(name = "personScore", onDelete = Column.ForeignKeyAction.CASCADE)
        public Score personScore;

        public Person() {
            // Notice how super() has been called to perform default initialization
            // of our Model subclass
            super();
        }

        public Person(String personName, int personAge, Score personScore) {
            super();
            this.personName = personName;
            this.personAge = personAge;
            this.personScore = personScore;
        }

        @Override
        public String toString() {
            // TODO Auto-generated method stub
            return "Name: "
                    + personName
                    + " Age: "
                    + personAge
                    + " "
                    + personScore;
        }
    }

initalize MyApplication.java

package com.example.sinildatabasetest;

import com.activeandroid.ActiveAndroid;
import com.activeandroid.app.Application;

public class MyApplication extends Application{
     public static final String TAG = "SUNIL";
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();

        ActiveAndroid.initialize(this);
    }

}
sunil sarode
  • 154
  • 1
  • 13

0 Answers0