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
Fixes NullPointerExceptions due to callbacks in MainActivity #1039
Conversation
is this overlapping with #1038 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checks for null are there. if i view such code i understand @abdulwd suggesting to migrate to kotlin ;)
@sonusourav @abdulwd @prajurock is there a design problem as we need such null pointer checks all over the place? i fell over a comment saying: https://stackoverflow.com/questions/16437050/checking-if-a-view-null-before-setting-onclicklistener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good except one point for discussion.
|
||
public boolean checkNull(View view) { | ||
return view != null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, encapsulating such small functionality in a separate function is overkill. You are anyways going to write if(checkNull(view_name)){}
. Why not just if(view_name != null)
. Every function call has an overhead and hence I am not in favor of it. If readability is your main intention, then we might leave it like you have done but I find explicit check equally readable.
@soloturn Hi, So I went through the codebase a bit more after going through the Stackoverflow link. I must say that I might be wrong since I started yesterday only and hence am relatively new to this project. I think the problem is indeed a design issue.
case REQUEST_PREFERENCES:
if (resultCode == RESULT_RESTART) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
finish();
}
... more code.
|
@harshika-arya thanks for having a look! how would you recommend to implement this? |
Fixes #891 #895
Issues #891 and #895 have a common root to callbacks which gives NullPointerExceptions.
Changes:
Screenshots