gpt4 book ai didi

java - ListView Intent On Item Click Listener 停止应用程序错误

转载 作者:行者123 更新时间:2023-12-02 09:40:20 29 4
gpt4 key购买 nike

我有ListView。我想单击项目并更改 Activity 。 ListView 工作正常,但是当我单击任何项​​目时,应用程序将停止并关闭。

ListView myListViewOfSongs;
String[] people;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListViewOfSongs = findViewById(R.id.songs);
people = new String[]{
"Mike Strong",
"Jennifer Anniston",
"Tom Bennet",
"Leander Paes",
"Liam Nesson",
"George Clooney",
"Barack Obama",
"Steve Jobs",
"Larry Page",
"Sergey Brin",
"Steve Wozniak"
};
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,people);
myListViewOfSongs.setAdapter(myAdapter);
myListViewOfSongs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(getApplicationContext(),PlayerActivity.class));
}
});

}

最佳答案

我已经检查了你的问题。您已使用 getApplicationContext() 启动 Intent。请更换getApplicationContext()context

替换代码

startActivity(new Intent(getApplicationContext(),PlayerActivity.class));

 Intent intent = new Intent(AccountActivity.this, LoginActivity.class);
startActivity(intent);

Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);

关于java - ListView Intent On Item Click Listener 停止应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57134683/

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