"What eh" / "how to solve" a "null object reference" error? What appears on the console?

0
When I try to use the code below (which alias I got with the help of OS friends) I get an error on the line:
asked by anonymous 31.01.2017 / 00:50

1 answer

3

Briefly, the NullPointerException exception is thrown whenever you try to access a object that has not been instantiated, or better initialized, until the moment of its call.

First thing to note is that you are declaring two variables of type Spinner , globally in your inner class and within onPreExecute() . Declare only once so that the error does not occur. Here's how your method onPreExecute() would look like:

@Override
protected void onPreExecute() {
    super.onPreExecute();
    spinner = (Spinner) findViewById(R.id.memo_confirmation_spinner );
    spinner.setOnItemSelectedListener(this);
}

Second factor is that as you are saying that the error is in this line below:

spinner = (Spinner) findViewById( R.id.memo_confirmation_spinner );

Try to notice in your out class if you are not calling your JSONOAsyncTask before setContentView() . If so, just reverse doing this:

setContentView(R.layout.sua_activity);
new JSONOAsyncTask.execute();
    
31.01.2017 / 01:29