尝试在空对象引用

时间:2018-04-21 10:33:44

标签: android nullpointerexception spinner android-arrayadapter object-reference

我得到例外 attempt to invoke virtual method 'void android.widget.spinner.setadapter(adapter) on a null object reference 我已经尝试了超过12个小时但没有解决方案。这个网站上有很多类似的问题,但没有一个可以帮助我。我不知道我错过了什么。请帮助我,节省我的时间。您的帮助将不胜感激。 以下是代码

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

0 个答案:

没有答案