androidlistviewgithubcrashbaseadapter

Electric Car Charging Android App crashes on start - custom list item and Adapter


I am doing a Udacity course on Android Development specifically in Networking atm. I am building an app that find the closest Electric Car Charging points and displays them in a listView. At the moment I am just trying to get the structure working before retrieving live data.

I am using a custom object - ChargePoint- which takes 5 inputs.

I am using a custom adapter - ChargePointAdapter - which translates the 5 bits of info onto the right places in a list_item.xml

My - MainActivity - stores the placeholder data, creates an adapter with the data, finds the listView from activity_main.xml and sets the adapter.

I dont get any errors, however my app crashes on start.

Here is a link to the project: https://github.com/Kovah101/ChargeMyCar

EDIT: On further inspection the app runs when I comment out the line:

chargePointListView.setAdapter(adapter)

which I assume means my custom adapter class isnt to blame? The only difference in the Log outputs from the running to non running version is

09-21 18:08:54.533 20790-20790/com.example.android.chargemycar I/Process: Sending signal. PID: 20790 SIG: 9

Any help would be greatly appreciated!


Solution

  • So there were a few little errors, DroiDev was correct in saying the adapter had caused the error, since commenting out that line allowed the app to run.

    I went through each part of my ChargePointAdapter and found TextView distanceTextView = (TextView) listItemView.findViewById(distance); which should have been R.id.distance, fixing that didnt solve my problem so I commented out the whole distance chunk to start a process of elmination through the app. First time and that solved the crash so the error was in

    TextView distanceTextView = (TextView) listItemView.findViewById(R.id.distance); String distance = Double.toString(currentChargePoint.getDistance()); distanceTextView.setText(distance);

    theoretically that all worked so I looked at my xml and my parent View had the id/distance not my textView, correcting that fixed everything, the Github is updated with the working code now too.

    Keep looking down the Rabit Hole (Thanks DroiDev)