我正在构建Android应用。我使用listview来显示数据并为项设置onClickListener。这是我的代码: -
listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(SongList.this, position, Toast.LENGTH_SHORT).show(); //shows error when try to get position
// Bundle bundle = new Bundle();
// Intent intent = new Intent(SongList.this, MainPlayer.class);
// intent.putExtra("pos",arrayList.indexOf(this));
// intent.putExtra("listItems",arrayList);
// startActivity(intent);
}
});
我想将数据发送到其他活动。但是当我尝试从列表视图中烘烤当前项的位置时,会发生Resource $ NotFoundException的错误。
错误日志
Process: com.android.jarvis.easysplay, PID: 15118
android.content.res.Resources$NotFoundException: String resource ID #0x6
at android.content.res.Resources.getText(Resources.java:322)
at android.widget.Toast.makeText(Toast.java:290)
at com.android.jarvis.easysplay.SongList$1.onItemClick(SongList.java:59)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1188)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3231)
at android.widget.AbsListView$3.run(AbsListView.java:4165)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)