Crash in ListView (Null object reference)

My app crashed and this is the logcat output. It appears to be an issue in the ListView item selection code.

FATAL EXCEPTION: main
Process: appinventor.ai_easrng.simpltalk, PID: 23730
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackgroundDrawable(android.graphics.drawable.Drawable)' on a null object reference
	at com.google.appinventor.components.runtime.ListView.onItemClick(ListView.java:425)
	at com.google.appinventor.components.runtime.ListView.onItemSelected(ListView.java:440)
	at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
	at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
	at android.widget.AdapterView.-wrap1(Unknown Source:0)
	at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:898)
	at android.os.Handler.handleCallback(Handler.java:790)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:164)
	at android.app.ActivityThread.main(ActivityThread.java:6626)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Hmm. Interesting that you were able to get a null pointer exception here. Was there anything interesting in particular with the item you selected? Could you reproduce the issue with just the ListView in a UI and nothing else?

Put here the aia project of the app that is causing this error.

Hello easrng

Some questions that might help us to help you:

  1. Was there an error message from the App? If yes, what exactly did that say?
  2. Is the List View in your App (a) a ListView or (b) a List Picker?
  3. Is the List View component the standard App Inventor one or an extension?
  4. Is the List View rather long - over a hundred items?
  5. Does the crash actually occur when the User is selecting from the List View?

Nope, it just crashed

A listview

It was the standard app inventor listview.

No, not that long.

I think it happened when I set the selected item index, but I'm not sure. The app was a chat app, the messages are put in the listview and the last item is selected to scroll it to the bottom. It had been working for a few minutes, then it crashed.

I'll try to repro and isolate the issue.

simpltalk.aia (80.7 KB) The crash was after several minutes of use, not sure if I will be able to repro. There are other known bugs especially with my handling of the textbox, but I'm fixing those.

Other bugs away from the ListView could be causing the crash.........

I kinda doubt it, the bug I see is very obvious when it happens (new error dialog every 5ms or so)

I can repro compiled + in simulator, just spam messages. Making a testcase...

Evan - if the App icon master image is 512 x 512 instead of 1024 x 1024, Is App Inventor still going to produce the icons set correctly?

Here you go! ListViewCrashTest.aia (1.9 KB) The rate makes a difference, not sure where the cutoff is.

So, just testing the App with easrng - the crash occurs when the ListView is being updated. I think there is a clash in there whereby a button event and a clock timer can try to update the list at the same moment.

easing is going to try modified code without a timer.

I tried with a webview quickly changing the webviewstring, that works too. This is not a clock issue.

Trust me, it is worth trying the code without the Clock Timer event competing with another event to run the same procedure.

@easrng, thanks for the test apps. We'll take a look and see what we can figure out.

Yes. The 1024x1024 is only needed for the iOS builds, and so the 512x512 will just be upsampled to 1024x1024 in that case.

1 Like