【发布时间】:2021-07-23 21:04:35
【问题描述】:
拜托,我在将 ArrayList 数据发送到 Activity 时遇到问题。
数据是保存在ArrayList 中的 URL,但在使用捆绑附加功能后,我收到空指针异常。我也尝试捕获异常,但我使用 get extra string 获得的数据仍然为空
// below is the code i used to pass the data
Bundle extras = new Bundle();
extras.putString("VidUrl",VideoLecturesUrl.get(position));
extras.putString("bookUrl",bookUrl.get(position));
extras.putString("VidTitle",titleList.get(position));
Intent intent = new Intent(getActivity(),DetailsView.class);
intent.putExtras(extras);
startActivity(intent);
// below is the receiving activity
Intent intent = getIntent();
extras =intent.getExtras();
if (extras!=null){
try {
Video_Url = extras.getString("VidUrl");
BookUrl = extras.getString("bookUrl");
Title = extras.getString("VidTitle");
Toast.makeText(this,Video_Url,Toast.LENGTH_SHORT).show();
Toast.makeText(this,BookUrl,Toast.LENGTH_SHORT).show();
Toast.makeText(this,Title,Toast.LENGTH_SHORT).show();
videotexTitle.setText(Title);
setTitle(Title);
setVideo(Video_Url.toString());
}catch (Exception e){
e.printStackTrace();
}
} else {
Toast.makeText(this, "the extrass is empty", Toast.LENGTH_SHORT).show();
}
【问题讨论】:
-
你到底在哪里得到 nullpointerexception ?
-
当我尝试将数据保存到变量以便我可以使用它时
-
即使当我尝试烘烤数据以确认其仍然是空白的空字符串时
标签: java android arrays android-studio android-fragments