gpt4 book ai didi

java - 我需要帮助,我的类(class)无法从我的数据库中获取数据

转载 作者:行者123 更新时间:2023-11-30 00:39:14 25 4
gpt4 key购买 nike

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

我需要帮助从数据库中获取数据。它不会显示创建 Activity 。这是通过图像显示的错误

demo

最佳答案

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

关于java - 我需要帮助,我的类(class)无法从我的数据库中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42810942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com