:java.lang.NullPointerException:尝试调用虚方法'java.lang.Object java.util.HashMap.get(java.lang.Object)'

时间:2015-02-28 18:15:31

标签: java android nullpointerexception activeandroid

我在下面的代码中得到空指针异常,就像我在评论中提到的那样。  我很困惑,为什么它如此需要帮助。  人员列表是否为空?  我试图显示人员列表,有人请解释这个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;
        }
    }

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

}

0 个答案:

没有答案