1

I'm am a newbie with Android development and using the following example to do something similar: https://stackoverflow.com/a/11626706/5724649

But am getting the following error: "Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference"when I try to set one of the radio button. Also mSource (which is an ArrayList) is null within getView(), so I see why I could get this error, but not sure as to how I should pass the arraylist to getView(). Please help.

Community
  • 1
  • 1
  • 2
    We need to see the exact code you are using, please add it to this question so we can easily see it without having to follow links. Please include any modifications you have made to that sample and the line number at which the error occurs. The line number should be shown in the error output. Thanks – EkcenierK Dec 28 '15 at 21:07
  • Did you initialize and populate the arraylist mSource = new Arraylist() – prashant Dec 28 '15 at 21:08
  • code sample please. Your app has logic we cant comprehend without sample code – Phillip Kigenyi Dec 28 '15 at 22:56

1 Answers1

0

The error is about you calling a method on an object which currently "null".

This will also throw the same error:

    String a = null;
    a.length(); // <<< This will cause an error, because a is null.

You should make sure the following line:

    mSource = new ArrayList<RowObject>();

is running before any of these lines:

    mSource.get(position).setFirstChecked(true);

    mSource.get(position).setFirstChecked(false);

    if (mSource.get(position).isFirstChecked()) {
A-S
  • 2,547
  • 2
  • 27
  • 37