0

i am getting exception attempt to invoke virtual method 'void android.widget.spinner.setadapter(adapter) on a null object reference I have tried more than 12 hours but got no solution. There are numbers of similar questions on this website but non of them could help me. I don't know what I am missing.Please please help me and save my time.Your help will be appreciated. Following is the code

private static String URL;
private static String URL2;
private ProgressDialog pDialog;
private List<DataFetcher1> List1 = new ArrayList<DataFetcher1>();
private List<DataFetcher2> List2 = new ArrayList<DataFetcher2>();

private ListView listView;
private GridView gridView;
private CustomListAdapter customListAdapter;
private CustomListAdapter2 CustomListAdapter2;
private Spinner spinner3;
private Context context;
private SwipeRefreshLayout mySwipeRefreshLayout;
public static final String PAGE_TITLE = "Tab2";
private String teamName;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_team_details);

    /*
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(R.layout.custom_action_bar_layout);
    View view = getSupportActionBar().getCustomView();
    */
    Bundle data = getIntent().getExtras();
    String TeamNameInSharePre = data.getString("TEAM_NAME");

    String[] Teams = {"DATA1","DATA2","DATA3","DATA4","DATA5","DATA6","DATA7"};
    Teams[0] = TeamNameInSharePre;
    spinner3 = (Spinner) findViewById(R.id.spinner3);
    ArrayAdapter<String> adapter_team = new ArrayAdapter<>(this,android.R.layout.simple_spinner_item, Teams);
    adapter_team.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    spinner3.setAdapter(adapter_team);      // Getting exception--> attempt to invoke virtual method 'void android.widget.spinner.setadapter(adapter)' on a null object reference

    listView = (ListView) findViewById(R.id.fixtures_list_view);
    customListAdapter = new CustomListAdapter(this, fixtureList);
    listView.setAdapter(customListAdapter);         // Getting exception--> attempt to invoke virtual method 'void android.widget.spinner.setadapter(adapter)' on a null object reference

    gridView = (GridView) findViewById(R.id.players_list_container);
    playersCustomListAdapter = new PlayersCustomListAdapter(this, playerList);
    gridView.setAdapter(playersCustomListAdapter);           // Getting exception--> attempt to invoke virtual method 'void android.widget.spinner.setadapter(adapter)' on a null object reference
Sandeep Kumar
  • 69
  • 1
  • 10
  • It would seem that the `` with ID `spinner3` is not in the `activity_team_details` layout. – Mike M. Apr 21 '18 at 10:35
  • Make sure that your 'spinner3' belongs to 'activity_team_details' layout. – Constantin N. Apr 21 '18 at 10:37
  • activity_team_details has an spinner named spinner3 – Sandeep Kumar Apr 21 '18 at 10:45
  • Are you certain it's the layout that's being loaded? That is, do you have multiple versions of `activity_team_details`; e.g., one for landscape, and another for portrait? If not, and you're certain that `Spinner` is in the current layout, then try cleaning/rebuilding. – Mike M. Apr 21 '18 at 10:47
  • yes...i have multiple versions of this layout..i think you got the solution..please tell me the way how will i appreciate you if the code would run – Sandeep Kumar Apr 21 '18 at 10:55
  • You just need to make sure that every version contains a `` with `android:id="@+id/spinner3"`. – Mike M. Apr 21 '18 at 10:58
  • 1
    @MikeM. Thank you..Code Runs..Thanks every one for your support – Sandeep Kumar Apr 21 '18 at 11:25

0 Answers0