Java 当我想从一个片段变成一个新的活动(Android)时,我的应用程序不断崩溃
因为我是新手,所以我在处理碎片方面遇到了麻烦。我现在的问题是,每当我想从一个片段切换到另一个活动时,我的应用程序总是崩溃。另外,我的一个函数无法工作和使用。如果有人能帮助我,我将不胜感激Java 当我想从一个片段变成一个新的活动(Android)时,我的应用程序不断崩溃,java,android,Java,Android,因为我是新手,所以我在处理碎片方面遇到了麻烦。我现在的问题是,每当我想从一个片段切换到另一个活动时,我的应用程序总是崩溃。另外,我的一个函数无法工作和使用。如果有人能帮助我,我将不胜感激 public class LibraryFragment extends Fragment { //Create a new SongCollection variable private SongCollection activateCollection = new SongCollection(); /
public class LibraryFragment extends Fragment {
//Create a new SongCollection variable
private SongCollection activateCollection = new SongCollection();
//This is the place where all the execution happens
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Make sure to put this statement for the last
return inflater.inflate(R.layout.fragment_library, container, false);
}
//When the user taps on the cover arts
public void handleSelection(View view){
String resourceId = AppUtil.getResourceId(getActivity(), view);
Song selectedSong = activateCollection.searchById(resourceId);
AppUtil.popMessage(getActivity(), "Now playing: " + selectedSong.getTitle());
sendDataToActivity(selectedSong);
}
//A method which directs user to the "Now Playing" page as well as transfer songs information to the next activity
public void sendDataToActivity(Song track){
//An intent which directs user to the next activity
Intent toNowPlayingPage = new Intent(getActivity(), PlaySongActivity.class);
//Store the song information to be sent over to the next page
toNowPlayingPage.putExtra("id", track.getId());
toNowPlayingPage.putExtra("title", track.getTitle());
toNowPlayingPage.putExtra("artist", track.getArtist());
toNowPlayingPage.putExtra("fileLink", track.getFileLink());
toNowPlayingPage.putExtra("coverArt", track.getCoverArt());
//Initiate the intent
startActivity(toNowPlayingPage);
}
}在视图上展开布局,并在调用的方法handleSelection(视图)上传递视图对象;在onCreate()中。 因为您没有调用handleSelection()方法;
视图中没有onClicklistener添加堆栈跟踪,这样人们就可以理解确切的错误。Hi Yong,感谢您在stack overflow中发布,如果您发布错误屏幕截图以及要分析的代码段,这将非常有用。