Issue with Android contact list, problem with Asynctask and setting the adapter

Currently, I am working on developing a GPS app that includes a contact list feature for connecting with other individuals. As a newcomer to Android Studio, I am encountering some challenges in resolving an issue. Initially, I successfully implemented the map and GPS functionality; however, I am now facing an error with the contact list feature.

The contact list is accessible through a popup menu triggered by the contacts button on the homepage. Unfortunately, I consistently encounter an error when attempting to access the contact list.

The error message logged is as follows: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

Here is the snippet of the MainActivity code:

 [code snippet provided] 

Additionally, here are the relevant details from the AndroidManifest file:

 [AndroidManifest details] 

Moreover, I have included the SelectUser and SelectUserAdapter classes for reference:

 [SelectUser and SelectUserAdapter class details] 

Lastly, the activitymaps.xml layout file and contactlist.xml and contactview.xml layout files have been included to provide a better understanding of the app's UI.

 [activitymaps.xml, contactlist.xml, and contactview.xml details] 

Upon encountering the error, the stack trace generated is:

 [Error stack trace details] 

Answer №1

Your activitymaps.xml does not include a ListView element with the id contacts_list.

Update:

Based on the code you provided, it seems like modifying the initial lines of the "showSortPopup" function as shown below may resolve your issue:

// Inflate the popup_layout.xml
RelativeLayout viewGroup = (RelativeLayout) context.findViewById(R.id.ContactLayout);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.contactlist, viewGroup);

selectUsers = new ArrayList<SelectUser>();
resolver = this.getContentResolver();
listView = (ListView) layout.findViewById(R.id.contacts_list);

phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
LoadContact loadContact = new LoadContact();
loadContact.execute();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React: A guide to properly utilizing PropTypes inheritance

I've created a wrapper component for React Router Dom and Material UI: import Button from '@material-ui/core/Button'; import React from 'react'; import { Link as RouterLink } from 'react-router-dom'; const forwardedLink ...

Using jsdom as a package in a Meteor application is not possible

Recently, I came across an issue with my packages.json file. It looks like this: { "jsdom" : "0.8.0", "request" : "2.25.0" } As part of my project, I have the following code snippet: if (Meteor.isServer) { Meteor.startup(function () { var _ ...

Bootstrap modal fails to appear on screen

Using PHP, I generate a link from the controller. The link is stored in $retailer["url"] as 0125myimage.jpg <a onClick="crop('.$retailer["url"].')" data-target="#styledModal3" href="#" class="fa fa-edit lupa"></a> Here is my JavaSc ...

What could be the reason behind getting a useLayoutEffect error when using renderToString to render a Material-UI component?

Currently, I am utilizing React version 16.12.0 along with @MaterialUI/core version 4.8.1. The challenge I am facing involves creating a custom icon for a React Leaflet Marker. The icon in question is a Fab component sourced from Material-UI. In order to ...

What type does a React stateless functional component Flow return?

If I have a structure like this const RandomComponent = (props) => ( <div> <SomeSubComponent id={props.id} /> <AnotherSubComponent type={props.type} /> </div> ) How do I specify the return type using Flow, i.e., wha ...

I am facing difficulties in adding dynamic content to my JSON file

I've encountered a challenge in appending new dynamic data to a JSON file. In my project, I receive the projectName from an input form on the /new page. My API utilizes node.js's fs module to generate a new JSON file, where I can subsequently add ...

Android FIDO - ERROR 403 The request received could not be authenticated

I am currently developing a demo android app (technically using Flutter, but this specific code is in native Java). The main purpose of this app is to showcase the process of logging in using FIDO authentication. However, I have encountered an issue duri ...

Tips for displaying a nested JSON array in a table format?

https://i.sstatic.net/BvAEx.png I'm working with a JSON array and need to display the data in a table. My question is, how can I insert 'transactionData' inside the main object? Essentially, I want the object structure to be: { completeTime ...

Adding a Javascript file to the requirejs-config.js file in Magento 2

How can I properly load a JS file using requirejs? <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script> Here is my requirejs-config.js file: var config = { paths: { mod ...

Encountering Difficulty Accessing Index.ejs with Express.js

Currently, I am enrolled in a Linkedin course that focuses on building websites using express.js. I have encountered an issue where my index.ejs page is not rendering properly, as the server keeps loading my index.html page instead. I have tried searching ...

Fluctuating and locked header problem occurring in material table (using react window + react window infinite loader)

After implementing an Infinite scrolling table using react-window and material UI, I have encountered some issues that need to be addressed: The header does not stick to the top despite having the appropriate styles applied (stickyHeader prop). The header ...

Is it possible to adjust the width of the comment box on the Facebook "Like" button?

Is there a way to set the width of the comment box that appears after clicking the Facebook "Like" button? I know how to adjust the width of the button itself and related content, but can't find any options for the comment box: I've tried overri ...

Send in the completed form with your chosen preferences

Is there a way for me to submit a form with the selected option? My backend code is set up to work when using inputs: <input id="id_value_0" name="value" type="radio" value="1" /> <input id="id_value_1" name="value" type="radio" value="2" /> ...

Utilizing JSON data to populate a modal window in HTML

How can I incorporate JSON data into an HTML modal window? I have a set of 12 buttons, and when a user clicks on one, I want to display the corresponding month's information from a JSON file. let myJson; $(`button`).on(`click`, function() { let ...

How can we effectively utilize LESS variables in styles.less when working with LESS files within components in Angular versions 6 or 7?

Running Angular version 7.0.0 will generate a folder structure typical for "ng new". Below is the content of my styles.less file: @personal-black: #0000; This snippet shows the content of my app.component.less file: ...

Exploring the synergies of Remark and Rehype plugins alongside MDX in Next.js powered by @next/mdx

I’ve been experimenting with Github Flavored Markdown using @next/mdx, but I’m struggling to understand how to use plugins alongside the code. Here’s a breakdown of what I’ve attempted so far: (I’m following the instructions from the Next.js Doc ...

What is the most effective way to retrieve nested JSON data in an Android app using Java?

If I have a JSON object structured like this: { "weather:{ "sunny": "yes" "wind": "48mph" "location":{ "city": "new york" "zip": "12345" } } "rating": "four stars" } What is the method to access the city name within this nested s ...

What could be causing my code for displaying Triangular Numbers to malfunction?

I'm having trouble getting my code to correctly print out Triangular Numbers according to the formula. It seems to only loop the number 1. What could I be doing wrong? Any ideas on what mistake I might have made? public class Triangular{ public ...

Iterator: The final element in Java's rearview mirror

Is it similar to C++ in Java, where the iterator ends up at the position one past the last element? while (iterator.hasNext()) { String color = iterator.next(); } For example, in C++, we have: Blue Green Purple ^ ^ ^ ^ begin e ...

Adjust the size of an IFRAME to eliminate scrollbars from appearing

My webpage features an iframe that needs to be resized dynamically each time its contents change in order to eliminate scrollbars. The content inside the iframe frequently changes without altering the URL. I desire for all the content within the frame to b ...