Skip to content

Tag: android

NullPointerException on validating email

I am writing a unit test to check the email validation logic. The logic is throwing null pointer exception when you run the test. But it works fine with emulator. Can someone help me solving this? Below is my unit test. The error I am getting is, Answer android.util.Patterns.EMAIL_ADDRESS.matcher(email).match…

How to exclude all files under a directory in Gradle?

For example, this one will exclude 1 file. But how to exclude all file under a directory? like: org/apache/commons/codec/language/bm/ folder? . does not work 🙂 Answer wild card can be used to enforce action to multiple file in directory. See this:- You can also exclude a file/directory with out specifying the…

Android Data Binding pass arguments to onClick method

Is it possible to pass custom arguments to onClick method using the Data Binding Library? I have my layout xml file where I need to use the onClickListener: and I a have my click handler code here: Is it possible to pass my CategoryViewModel object from xml to click handler? Answer You can use a lambda expres…

File structure listing as Json

How can I get a local directory listing as a Json? So If I provide a folder, I want to see all its subfolders and files in a json tree type object. Please note: I don’t want just the list with file paths. Thank you! Answer So @CommonsWare put me in the right direction and I was able to do

Cannot resolve method ‘findViewByID(int)’ in Android Studio

I only just started coding for androud, but I’ve been getting the error: “Cannot resolve method ‘findViewByID(int)’” in android studio I can’t seem to find out what is wrong, have tried setting contentView, implementing OnClickListenener, but none of these fixed anything. full co…

ListFragment Not displaying data from List

After I try to open the navigation drawer and go to a different tab and then go back to it. It is not showing data in a list once again. Main Activity UniverseListing Glimpse List Fragment Answer You create an Activity instance that isn’t managed by the Android life cycle, so the Arraylist that you want…