spinner设置适配器的时候就出现了空指针异常
package com.example.spinner;
import java.util.ArrayList;
import java.util.List;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
private TextView textView;
private Spinner spinner;
private List<String>list;
private ArrayAdapter<String>adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView)findViewById(R.id.textview);
spinner=(Spinner) findViewById(R.id.spinner);
list=new ArrayList<String>();
list.add("Beijing");
list.add("Shanghai");
list.add("Guangzhou");
list.add("Shenzhen");
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
}