我需要帮助,我的班级不会从我的数据库中获取数据

时间:2017-03-15 13:16:33

标签: java android android-sqlite

public class ActivityList extends Activity {

    SQLiteHandler db;

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

        db = new SQLiteHandler(this);

        BackGroundTask backGroundTask = new BackGroundTask(this);
        backGroundTask.execute("get_info");
        //populateActivityList();
        registerClickCallBack();
    }

    private void registerClickCallBack()
    {
        final ListView list = (ListView) findViewById(R.id.listActivities);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                try{
                    String name = (String) list.getAdapter().getItem(position);
                    NewActivityDB activities = db.changeStatus(name);
                    Intent intent = new Intent(ActivityList.this,OnGoingActivity.class);
                    intent.putExtra("activity",activities);
                    startActivity(intent);
                    //finish();

                }catch(Exception e){
                    Toast.makeText(ActivityList.this, "ActivityView: "+e.toString(), Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}

我需要帮助从数据库中获取数据。它不会显示创建活动。通过图像出现错误

demo

1 个答案:

答案 0 :(得分:1)

代码中的这一行:NewActivityDB activities = db.changeStatus(name);正在导致它。 异常意味着:您正在尝试将String值分配给实体对象。因此,更改该行应该可以解决您的问题。所以基本上db.changeStatus(name)返回一个字符串,并且你试图将它分配给一个对象,因此ClassCastException