0

正如我在评论中提到的,我在下面的代码中遇到空指针异常。我很困惑为什么会这样并且需要帮助。人员列表是否为空?我正在尝试显示人员列表,请有人解释此 execute() 在活动 android 中的工作原理。

谢谢。

@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);

}

人类

 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;
        }
    }

初始化 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);
    }

}
4

0 回答 0