The exception guides you straight to the location where this error is coming from:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
As per your code, there can be two ways to fix this,
keywordlist = findViewById(R.id.keywordlist);
Either, check that this keywordlist view has been inflated in the activity. Otherwise, if you are deep down in the hierarchy, try accessing this view from the view that your control is currently inside — happens with inflated views and layouts.
There are several other things that can go wrong, so best hands are still yours to find the bug, try debugging and seeing why is that object null.
I shared a link for a thread that talks about a common problem in Android programming. The function findViewById() tries to capture the View from the current context or the scope, which is mostly the Activity. When you try to find the view by the ID of, keywordlist, runtime will try to find the view inside the current context, most likely, Activity you are currently inside.
For example, you just inflated the activity_main layout, but you are having the ListView defined inside another layout file,
This is one of the problems that you might be facing, because your View is not even inflated — unless your activity_main tries to inflate this view internally, which I am not sure of as you did not show the code for that activity.
I did not run the code, or analyze it completely, but most likely there are two things that might go wrong here,
The view does not get inflated, or it not found in the context you are trying to look under.
You are not using the correct ID of the element.
Also check if the ID is being used correctly and for the view you are expecting to be there. Debug, debug, debug. Also try to listen on a click listener of the view and find the ID or parents of that to check the hierarchy of the elements.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
I'm looking for somebody to write app with in AS. All data/project is ready just programming left to be done. Since I'm only 'a year experienced' beginner, I wish to work with somebody more advanced in java-android programming. There is a big chance of success so we can work as co-creators in coming projects too.
Can you please explain what type of project it is? Actually I have experience in building projects for some particular domains. Please let me know about the industry and other details that you can share.
I have a lot of database text files arranged inside folders and subfolders. I want to restrict the files from accessing externally from the app. So asset/ raw folder is the best option and each file size is less than 50kb. And in asset folder the arrangement is similar to file system and in raw folder its based on id's. So i opt for asset folder.
The selection of the database file is done by the user. So a search dialog window for browsing the file would be the better option. But i don't find any sample code for accessing a asset file system using dialog window. Is it possible?.
Actually I need a sample code for accessing a file in asset folder with the help of file browsing dialog window not this.
Anyway i dropped the plan, instead of file browsing dialog window, listview will be a better option. Files and folders inside the asset folder can be displayed in ListView and user can select what they need.
Hello all. From out of 10 dialogs, I need one of the dialogs to start with landscape orientation. No other activity, fragment and dialog will be started with landscape orientation except this one dialog.
I have absolutely no idea how do I make this happen? Do I create some custom control ?
I have an Android application where customers can purchase and put orders
Every customer can put order and I just have one `JSON` file in the `PHP` server to collect the orders from different customers
The problem is if one customer puts his/her order, the `JSON` file shall be locked in order to prevent collision and if it is locked, how can another customer put order at the exact same time?
To solve this issue, and for test, I decided to have a folder in the server where every customer (who is going to put an order) can put his unique ID there (uploading a text file with the name of the customer's ID) and I just read that folder to see who has put any order and then I delete the file which was uploaded by the customer indicating he/she has just put an order to be ready from another order from that customer
(every customer creates a folder with his/her unique ID name to put detailed list of his/her orders and this is handled by PHP code)
It works fine but does not seem to be a true manner from performance point of view
one `JSON` file in the `PHP` server to collect the orders from different customers
Unlike an ASP or PHP page, a JSON file does not "collect" anything. Based on what you've provided, unless you are doing something totally wrong, there should be no way for it to become locked. If multiple clients request the same JSON file, the web server will deliver the file to each client without issue.
The whole "upload a file containing a customer number and/or order" approach seems way wrong to me.
When you make contact with a web server, a one-on-one relationship has been established. When you interact with a web page (e.g., PHP file), you are doing so with your "copy" of it. If some other client is also interacting with that same page, again it's on their own "copy" of it. The web server keeps track of all those connections (up to some upper limit).
Admittedly, I may be completely wrong on this. It borders on ecommerce which I have zero experience with. But what you are doing just seems kludgy and prone to error.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles