0
I am trying to use a method that returns a list, when using this same method inside the mainactivity where it was created everything works well, but when trying to access it in a fragment of the Nullpointerexception error.
log:
06-24 14:29:11.829 32645-32645/? D/Logzin: chamou api
06-24 14:29:11.839 32645-32645/? D/Logzin: colocou a playlist na mplaylist
06-24 14:29:11.839 32645-32645/? D/Logzin: catch java.lang.NullPointerException
[ 06-24 14:29:11.859 32645:32645 D/ ]
HostConnection::get() New Host Connection established 0xb98ce920, tid 32645
[ 06-24 14:29:11.869 32645:32645 W/ ]
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1
Method on Main:
public List<PlaylistItem> getlistavideos(){
try {
mplaylistItems = playlistItems;
Log.d(TAG,"colocou a playlist na mplaylist");
}catch (Exception e){
Log.d(TAG,"Catch Main " + e);
}
return mplaylistItems;
}
How am I trying to call you in Fragment:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragmentlistavideos,container,false);
/*mList = new ArrayList<String>();
mList.add(mList.size(),"Um");
mList.add(mList.size(),"Dois");
*/
try {
int tamanho= ((MainActivity)getActivity()).getlistavideos().size();
Log.d(TAG,"Tamanho da Lista "+ tamanho);
}catch (Exception e){
Log.d(TAG,"catch "+e);
}
return v;
}
As already answered in 2 other questions about this same list you made. You have to first make the list query call and once it is filled in you create the Fragment, or you have to fill in the list within the Fragment
– Grupo CDS Informática