0

没有错误

spinner = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view,
 int position, long id) {

 temp_material=parent.getItemAtPosition(position).toString();

 }


 @Override
 public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

} 
});

spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent2, View view,
int position, long id) {

temp_space=parent2.getItemAtPosition(position).toString();

}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

} 
}); 

错误...空点异常!▼</p>

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
    // setContentView(R.layout.test_start_passvie);

      try{
    spinner = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);

    temp_mode_state = getIntent().getStringExtra("select_key");

      if(temp_mode_state.equals("0")){
      setContentView(R.layout.test_start_passvie);
      }
      if(temp_mode_state.equals("1")){
      setContentView(R.layout.test_start_passvie_mg);
      }
      if(temp_mode_state.equals("2")){
      setContentView(R.layout.test_start_passvie_space);
      }
       try{
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
    int position, long id) {

    temp_material=parent.getItemAtPosition(position).toString();
    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

    } 
    });

    spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> parent2, View view,
    int position, long id) {

    temp_space=parent2.getItemAtPosition(position).toString();

    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

    } 
    }); 
       }catch(Exception e){}


            SharedPreferences ref_sig_pref=PreferenceManager.getDefaultSharedPreferences(this);
    ref_sig_pref_str = ref_sig_pref.getString("orgin_sig_preference", "-20");

    DBHelper = new DatabaseHelper(this, DATABASE_NAME , null , 1);

    start_sig_info_pass = (TextView) findViewById(R.id.start_sig_info_pass);
    info_ssid = (TextView) findViewById(R.id.textView7);
    info_ipaddrs = (TextView) findViewById(R.id.textView6);

    wifimanager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wInfo = wifimanager.getConnectionInfo();
    @SuppressWarnings("deprecation")
    String ip_add =  Formatter.formatIpAddress(wInfo.getIpAddress());

    info_ssid.setText(wInfo.getSSID());
    info_ipaddrs.setText(ip_add);


      }catch(Exception e){setContentView(R.layout.test_start_passvie);}

    RadioGroup rd = (RadioGroup) this.findViewById(R.id.radioGroup1);
    rd.setOnCheckedChangeListener(this);

如果您单独实施,它会很好地工作。但是,一起执行,出现错误

spinner.setOnItemSelectedListener(new OnItemSelectedListener() { <- Nullpoint Exception help me... TT

4

1 回答 1

1

在第二个代码示例中查找微调器之前,您尚未调用 setContentView()。

微调器将为空,稍后尝试使用它们会给您 NullPointerException。

于 2013-08-06T14:07:42.823 回答