Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null pointer exception when displaying SearchFragment #6558

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ public void onViewCreated(@NonNull final View rootView, final Bundle savedInstan
initSearchListeners();
}

private void updateService() {
try {
service = NewPipe.getService(serviceId);
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this,
"Getting service for id " + serviceId, e);
}
}

@Override
public void onStart() {
if (DEBUG) {
Log.d(TAG, "onStart() called");
}
super.onStart();

updateService();
}

@Override
public void onPause() {
super.onPause();
Expand All @@ -250,13 +269,6 @@ public void onResume() {
}
super.onResume();

try {
service = NewPipe.getService(serviceId);
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this,
"Getting service for id " + serviceId, e);
}

Comment on lines -253 to -259
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. onResume() is called when you change service? then it should be updated onResume()? anyway search & switching service works

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@B0pol Did you figure something out here to merge this? It seems you had a question that wasn't resolved 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway search & switching service works

if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
}
Expand Down Expand Up @@ -428,6 +440,12 @@ public void onCreateOptionsMenu(@NonNull final Menu menu,
int itemId = 0;
boolean isFirstItem = true;
final Context c = getContext();

if (service == null) {
Log.w(TAG, "onCreateOptionsMenu() called with null service");
updateService();
}

for (final String filter : service.getSearchQHFactory().getAvailableContentFilter()) {
if (filter.equals(YoutubeSearchQueryHandlerFactory.MUSIC_SONGS)) {
final MenuItem musicItem = menu.add(2,
Expand Down