NullPointerException on getChildrenCount() of BaseExpandableListAdapter - java

I am using BaseExpandableListAdapter and trying to do a dynamic list, where elements appears and disappears when you check or uncheck other elements. The group is an ArrayList of an object tha I made calle Mode, and children are a HashMap like that: HashMap> children.
The problem comes when I actualize the list to add children and they are added perfectly, but when I check other elements and the new children must disappear the program give me a NullPointerException in the method getChildrenCount(). I am actually using the notifyDataSetChanged() in both cases, when I am adding and when I am removing.
This is a piece of my code (the important part is that if I find another Mode object with the same parent ID in the DB I must to delete the old one):
cbMode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isSelected = modeDao.rbIsAlreadySelected(currentChild);
if(!isSelected) {
//if checked uncheck all the children of the same parent AND delete the children
Mode oldMode = modeDao.isThereAnotherRB(currentChild.getIdFather());
if(oldMode != null){
uncheckTheOldCB(oldMode);
setFalseOnCb(oldMode);
modeDao.deleteMode(oldMode);
deleteModeChildren(oldMode);
}
//AND insert it on the DB
modeDao.setSelectedMode(currentChild);
currentChild.setChecked(true);
//if has children show them
if(currentChild.hasChildren() == 1){
setNewFatherMode(currentChild);
}
}else {
//if unchecked delete this from the DB
modeDao.deleteMode(currentChild);
deleteModeChildren(currentChild);
currentChild.setChecked(false);
}
notifyDataSetChanged();
}
});
It shows as how I delete the children:
private void deleteModeChildren(Mode oldMode){
for (Map.Entry<Mode, ArrayList<Mode>> entry : children.entrySet()) {
Mode currentMode = entry.getKey();
if(currentMode.getId() == oldMode.getId()) {
children.remove(entry.getKey());
break;
}
}
}
And this is how I overrided the getChild method:
#Override
public Object getChild(int groupPosition, int childPosition) {
return this.children.get(this.parents.get(groupPosition))
.get(childPosition);
}
This it the track of the exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at com.iurban.iurbanapp.Adapters.NewModesAdapter.getChildrenCount(NewModesAdapter.java:63)
at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:563)
at android.widget.ExpandableListConnector.access$000(ExpandableListConnector.java:50)
at android.widget.ExpandableListConnector$MyDataSetObserver.onChanged(ExpandableListConnector.java:857)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.widget.BaseExpandableListAdapter.notifyDataSetChanged(BaseExpandableListAdapter.java:56)
at com.iurban.iurbanapp.Adapters.NewModesAdapter$3.onClick(NewModesAdapter.java:223)
at android.view.View.performClick(View.java:4787)
at android.widget.CompoundButton.performClick(CompoundButton.java:120)
at android.view.View$PerformClick.run(View.java:19873)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
And this is the getChildCount method:
#Override
public int getChildrenCount(int groupPosition) {
return children.get(parents.get(groupPosition)).size();
}

Ok, after a while I just to realise that I was deleting the children but not the corresponding parent of it. So, the getChildCount method gave me an error because the groupCount value were 4 when it must be 3.
Thank you all!

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
This tells you that the size() method is what threw the NPE, so there's a good chance that it is the list which is null.
Double check that it is indeed initialised.

Related

Null Pointer Exception thrown when calling .show() on MediaController

I found this question was marked as duplicate for one about how to prevent Null Pointer Exceptions. For clarification, the problem is that the library is throwing it. My variable isn't null. More specific help about the library is more helpful.
I am creating an app for playing music. I am trying to make use of the MediaController class to add controls to the song being played. However, when I run the .show() function, I get a Null Pointer Exception.
Here is the code for the MediaController:
public void onViewCreated(#NonNull final View view, #Nullable Bundle savedInstanceState) {
MediaController timer = view.findViewById(R.id.song_progress);
timer.setMediaPlayer(new MediaController.MediaPlayerControl() {
#Override
public void start() {
MainActivity.playingSong.start();
}
#Override
public void pause() {
MainActivity.playingSong.pause();
}
#Override
public int getDuration() {
return MainActivity.playingSong.getDuration();
}
#Override
public int getCurrentPosition() {
return MainActivity.playingSong.getCurrentPosition();
}
#Override
public void seekTo(int pos) {
MainActivity.playingSong.seekTo(pos);
}
#Override
public boolean isPlaying() {
return MainActivity.playingSong.isPlaying();
}
#Override
public int getBufferPercentage() {
return 0;
}
#Override
public boolean canPause() {
return true;
}
#Override
public boolean canSeekBackward() {
return true;
}
#Override
public boolean canSeekForward() {
return true;
}
#Override
public int getAudioSessionId() {
return MainActivity.playingSong.getAudioSessionId();
}
});
timer.setAnchorView(view);
timer.setEnabled(true);
timer.show();
}
Here is the error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.luner.mobilemusic, PID: 2021
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.measure(int, int)' on a null object reference
at android.widget.MediaController.updateFloatingWindowLayout(MediaController.java:173)
at android.widget.MediaController.show(MediaController.java:363)
at android.widget.MediaController.show(MediaController.java:314)
at com.luner.mobilemusic.Playlist$Song$PlayFragment.onViewCreated(Playlist.java:271)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:892)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Why is this happening? Is there a good way to fix this, or should I use a different class completely? I would very much appreciate any code examples you might have.
Also, I found that removing the setAnchorView(view) prevented the error, but then caused no MediaController to appear.
Edit
After doing a more thorough search, I found two things:
The line numbers aren't accurate for some reason; the line for updateFloatingWindowLayout appeared inside a different method.
The culprit is the mDecor variable, which while running the setAnchorView method is set to the view variable. However, the view variable can't be null, as that would have caused an exception before getting to the show function. Thus, I still can't quite figure out the source of this ... the mDecor variable must somewhere be set to null, but only when I add a custom anchor view.
Edit 2
I have made lots of changes to the program at this point, so I am unable to test if a solution works. However, feel free to post an answer to help anyone else with the issue. I will accept any answer with a good amount of upvotes, as the upvotes signify that the solution worked. Thanks to everyone who tried to help!

IndexOutOfBoundsException when adding items to specific index through LiveData observer

I'm working on a ViewPager fragment that uses FragmentStatePagerAdapter as the adapter. The Adapter's data is a List object that comes from the database, and I am observing the query with MediatorLiveData.
MediatorLiveData merges six different lists that I have for one day and turns them into one list that is used by the Adapter.
I want to add an item to the List to a specific index and update the UI dynamically. The observer notifies the adapter when an item is added and the update works fine, however when I try to do it on a specific index, calling notifyDataSetChanged() causes an IndexOutOfBoundsError.
I initialize the adapter with a list as follows:
public MealDetailsPagerAdapter(FragmentManager fm, List<Long> list, long date, MealViewModel vm) {
super(fm);
this.mealIdList = list;
this.date = date;
this.model = vm;
}
Where MealViewModel is not relevant to this question, it is used on the fragment that the adapter is creating. The list changes are done by another viewmodel.
Here's a code that works correctly:
public void changeItems(List<Long> list, long date) {
if(this.date != date){
this.mealIdList = list;
notifyDataSetChanged();
return;
}
mealIdList.addAll(list);
mealIdList = removeDuplicates(mealIdList);
System.out.println(Arrays.toString(mealIdList.toArray()));
notifyDataSetChanged();
}
And the observer that calls it:
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewModel.getMealIdsInDay().observe(getViewLifecycleOwner(), longs -> {
myAdapter.changeItems(longs, mCurrentIndexDay);
if(isResumed){
mViewPager.setCurrentItem(myAdapter.getPageIndexForMealId(mViewModel.getMealId()));
isResumed=false;
}
updateIndicator(mViewPager);
});
}
Where isResumed is false by default, however if the user adds a new Meal isResumed is changed to true and the viewPager's current position gets changed to the created Meal's position.
However, with the working code, the created Meal's position will always be at the end of the adapter's List because of addAll(). I want to add the meal to a specific position, but if I get the index with mViewPager.getCurrentItem() and send it to the method as follows:
mealIdList.addAll(index, list);
the addAll itself works, but notifyDataSetChanged() causes an IndexOutOfBoundsError.
Here's the complete stack trace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: fi.seehowyoueat.shye.debug, PID: 14148
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.set(ArrayList.java:453)
at androidx.fragment.app.FragmentStatePagerAdapter.destroyItem(FragmentStatePagerAdapter.java:147)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1212)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:669)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
at androidx.viewpager.widget.ViewPager.dataSetChanged(ViewPager.java:1086)
at androidx.viewpager.widget.ViewPager$PagerObserver.onChanged(ViewPager.java:3097)
at androidx.viewpager.widget.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:291)
at fi.octo3.shye.view.viewpagers.MealDetailsPagerAdapter.changeTheItems(MealDetailsPagerAdapter.java:87)
at fi.octo3.shye.fragments.MealDetailsFragment.lambda$onActivityCreated$0(MealDetailsFragment.java:223)
at fi.octo3.shye.fragments.-$$Lambda$MealDetailsFragment$XB4Svnx84FE6kVa5Gzle01e8F3o.onChanged(Unknown Source:4)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
at fi.octo3.shye.models.viewmodel.-$$Lambda$2CouvY7DQv4NA0nk6EMoH6jUavw.onChanged(Unknown Source:4)
at androidx.lifecycle.MediatorLiveData$Source.onChanged(MediatorLiveData.java:152)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6748)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Looking at it, it seems that the problem is somehow caused by the LiveData, but I'm not sure how to fix it. If you want to look at the method that updates the MediatorLiveData that I have it's here:
private void refresh(long key){
if(groupsAndMealsMap.get(key) != null){
//remove source and then value from map
liveDataMerger.removeSource(groupsAndMealsMap.get(key));
groupsAndMealsMap.remove(key);
//add new value to map and add it as a source
groupsAndMealsMap.append(key, mealIdsInGroup);
liveDataMerger.addSource(groupsAndMealsMap.get(key), liveDataMerger::setValue);
}
}
refresh() is called by addItem() that gets an updated List of Meals from the database (list being mealIdsInGroup) and liveDataMerger consists of six LiveData> objects.
Any help will be appreciated. Thank you!
EDIT
Here's the addItem() method, as you can see the service executor waits for the operation to be done before moving on to the refresh() method.
public void addItem(Meal meal, long mealGroupId){
ExecutorService service = Executors.newCachedThreadPool();
service.execute(() -> {
setMealId(db.mealDao().insertMealIntoGroup(meal, mealGroupId));
mealIdsInGroup = db.mealDao().loadMealsWithinGroup(mealGroupId);
});
service.shutdown();
try {
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
refresh(mealGroupId);
}
I suspect that the issue occurs because the insert operation is not over yet.
Use a Handler to put a delay
new Handler(getMainLooper()).postDelayed(new Runnable() {
#Override
public void run() {
notifyDataSetChanged();
}
}, 500);
500 ms just for testing.
Does that issue occurs no matter of what position you're in?
Because if you are in position 0 of the adapter, the adapter didn't created the fragment that's in 3rd position yet.
Remember that the one of the main differences between ViewPagerAdapter and FragmentStatePagerAdapter is that the latter only creates 3 fragments at a time, and if you are in the first position or in the last, the adapter will only contain 2 instances of fragments.
Let me know if this solution helped you!

getApplicationContext on a null reference in AppCompatActivity using Picasso

I'm loading a picture from a url into a bitmap. This code below worked on previous classes that extended Fragment. This time, I'm just copying the code and trying to use it in a class that extends AppCompatActivity. The only difference is how I'm getting context.
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
handleLoadedBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
mContext = MyActivity.this;
Picasso.with(mContext).load(url).into(loadtarget); //giving me null
}
In the original code, where I used it in a Fragment, I had it as
Picasso.with(getActivity()).load(url).into(loadtarget);
So now, since this class extends AppCompatActivity, I thought I could use "this" or MyActivity.this but that didn't work. I've tried initializing a Context variable "mContext" in onCreate and right before I load the image into the bitmap (like above) but neither worked. I've tried this.getApplicationContext() and I've also tried to pass mContext as a parameter in the loadBitmap() method but that didn't work either.
My URL string is correct. I'm just not sure how to tackle this problem after trying, what seems like, everything.
Last piece of information, the exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:112)
at com.salty.seas.Driver.MyActivity.loadBitmap(MyActivity.java:144)
at com.salty.seas.Driver.MyActivity$1.onKeyEntered(MyActivity.java:61)
at com.firebase.geofire.GeoQuery$2.run(GeoQuery.java:126)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
In the comments to the question you said that the activity, the loadBitmap() belongs to, you actually instantiate yourself (in some other fragment) and use it as an utility class.
You should never create activites manually as they are managed by android and they have a lifecycle android maintains.
In your case the activity is not in a correct state (one of its internal fields is null), that's why you get NPE.
For utility methods create utility classes and call those from wherever you want.

Unable to retrieve query using parse

Hello I'm learning android and trying to display a customized ListView but it fails to load. The issue comes from my query as the list is empty. Please what did i do wrong as i was following parse example.
Below is my code using fragments to display the view as it fails to get inflated.
EventTab.java:
//query Events for current user
private void queryEventListFromParse(){
//Create query for objects of type "Event"
ParseQuery<ParseObject> query = ParseQuery.getQuery("Event");
// Restrict to cases where the author is the current user.
//pass in a ParseUser and not String of that user
query.whereEqualTo("author", ParseUser.getCurrentUser());
query.orderByAscending("createAt");
// Run the query
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> eventList, ParseException e) {
if (e == null) {
// If there are results, update the list of event and notify the adapter
Log.d(TAG, "Im in background"); //im able to display image
eventList.clear();
for (ParseObject event : eventList) {
eventList.add(event);
}
updateEventsList();
} else {
Log.d(TAG, "Event retrieval error: " + e.getMessage());
}
}
});
}
IMPORTANT UPDATE:
Thanks to Shadow Droid for pointing out the error. The reason why getView() fails to be called due to the List called evenList returning 0. This fails to get getView called and hence returns 0 and fails to display the list.
Below is error message when i commented eventList.clear();
Error from console:
12-05 04:52:10.511 11450-11450/com.example.davchen.skibuddies E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.davchen.skibuddies, PID: 11450
java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
at com.example.davchen.skibuddies.Fragments.EventTab$1.done(EventTab.java:87)
at com.example.davchen.skibuddies.Fragments.EventTab$1.done(EventTab.java:80)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
This is happening bcoz you are passing empty eventList to your adapter. There is confusion in parameter and global variable.
Global variable private List<Event> eventList; and it is initialized to empty in onCreate.
while as parameter in done method you are clearing the list which you get after parsing eventList.clear();
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> eventList, ParseException e) {
if (e == null) {
// If there are results, update the list of event and notify the adapter
Log.d(TAG, "Im in background"); //im able to display image
eventList.clear();
for (ParseObject event : eventList) {
eventList.add(event);
}
updateEventsList();
} else {
hence your adapter is getting count as zero and it will not call getView method.
As a solution I would suggest to check by commenting the eventList.clear(); and if works properly and still you require to clear list then go for different variable or parameter name

Null pointer exception when calling method from a different class

When I attempt to call the method loadUserList() from another class, I get the following error:
Attempt to invoke virtual method android.content.res.Resources
android.content.Context.getResources() on a null object reference
This is my loadUserList method
public void loadUserList()
{
final ProgressDialog dia = ProgressDialog.show(this, null, getString(R.string.alert_loading));
ParseQuery<ParseObject> query = ParseQuery.getQuery("Chat_User");
query.whereEqualTo("receiver", ParseUser.getCurrentUser());
query.include("sender");
query.findInBackground(new FindCallback<ParseObject>()
{
#Override
public void done(List<ParseObject> li, ParseException e)
{
dia.dismiss();
if (li != null)
{
if (li.size() == 0)
Toast.makeText(com.yarnyard.UserList.this, R.string.msg_no_user_found,
Toast.LENGTH_SHORT).show();
uList = new ArrayList<ParseObject>(li);
ListView list = (ListView) findViewById(R.id.list);
list.setAdapter(new UserAdapter());
list.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3)
{
loadUserList();
/*startActivity(new Intent(com.yarnyard.UserList.this, Chat.class)
.putExtra(Const.EXTRA_DATA, uList.get(pos).getUsername()));*/
}
});
}
else
{
Utils.showDialog(
com.yarnyard.UserList.this,
getString(R.string.err_users) + " "
+ e.getMessage());
e.printStackTrace();
}
}
});
}
This is how I am calling it
public void done(ParseException e)
{
UserList UserList = new UserList();
UserList.loadUserList();
}
My error log
07-30 14:14:56.219 13383-13383/com.anonimv2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.anonimv2, PID: 13383
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.content.ContextWrapper.getResources(ContextWrapper.java:85)
at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:74)
at android.content.Context.getString(Context.java:376)
at com.yarnyard.UserList.loadUserList(UserList.java:96)
at com.yarnyard.custom.CustomActivity.onOptionsItemSelected(CustomActivity.java:116)
at android.app.Activity.onMenuItemSelected(Activity.java:2882)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1131)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:587)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:141)
at android.view.View.performClick(View.java:4832)
at android.view.View$PerformClick.run(View.java:19839)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
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:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Any advice would be much appreciated.
Normal, non-static methods are called on objects, not on classes. This is a fine point that you really need to learn before using object oriented languages. Only then you will see, in practice, how you can connect objects by passing references.
The UserList objects that you construct in the done method is not the one you want to call, it's just an empty, uninitialized shell.
As I understand, you extend UserList from Context, right?
Then keep in mind that in Android never initial a Context object by yourself, it's framework's job..
In your case, because you create a context instance without attach to any baseContext, so when access to common resource, you got a NPE.
I guess that you are trying to move to a new Fragment or Actvity? Then read these link start activity switch fragment

Categories