I am implementing a database as I need to prepare the list or update it everytime I make some changes. I have a fragment on top of mainActivity and I can't perform the operations within the MainActivity
so some of the operations are to be done in MainActivity
and others in the fragment class
.
So in the fragment class which extends fragment has a method called preparelist()
, which updates the database and populate the data.
In my mainactivity I am performing a delete operations using the default overflow
menu item, but here I need to call the preparelist()
method in order to display the performed operations or the app has to be closed in order to diplay the operation that has been performed
I have tried the following code which is on the web
MyFragment fragment= (MyFragment)getSupportFragmentManager().findFragmentById(R.id.frag);
( (MyFragment)fragment).prepareList();
but this shows error
java.lang.NullPointerException: Attempt to invoke virtual method...on a null object reference
Basically what I want to know is how do I call the preparelist()
method within my MainActivity
without making any other abstract class or anything like that
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…