As the title suggests, my app currently crashes when I try to scroll on a listview. Everything works as intended when the listview is opened, but as soon as i scroll down, it crashes.
The listview is contained within a dialog box; The code snippet below shows how i initiliaze the dialog and the array adapter:
final Dialog startersDialog = new Dialog(context);
startersDialog.setContentView(R.layout.starters_dialog);
startersDialog.setTitle("Select Starter");
convStarters = (ListView) startersDialog.findViewById(R.id.scenarios);
greetingsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, chatBot.getGreetingsInputs());
convStarters.setAdapter(greetingsAdapter);
Code that gets invoked when i select an item of the list:
convStarters.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg3) {
userInput = adapter.getItemAtPosition(position).toString();
System.out.println("User Input Variable is: ");
userInputView.setText(userInput);
userInputView.setFocusable(false);
startersDialog.dismiss();
}
}
);
Dialog XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scenarios"/>
The error I'm getting is:
02-24 16:59:16.914 17612-17612/com.example.alex.projectui E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.alex.projectui, PID: 17612
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
at android.widget.AbsListView.obtainView(AbsListView.java:2823)
at android.widget.ListView.makeAndAddView(ListView.java:1884)
at android.widget.ListView.fillDown(ListView.java:713)
at android.widget.ListView.fillGap(ListView.java:677)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:7040)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:6478)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:559)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
I apologize if the question is rather straightforward, but I've been struggling with this problem over the past few days and I couldn't find any obvious or easy to follow resource that deals with such a problem.
Thanks in advance. Any response is much appreciated.
Check all values from chatBot.getGreetingsInputs().Check if there is not null elements in your list.
In this question Android App crashes after Scrolling down ListView for example, 2 last records was corrupted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With