没有错误
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
}
});
错误... Nullpoint异常!▼
@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(){&lt; - Nullpoint Exception 帮助我... T.T
答案 0 :(得分:1)
在查找第二个代码示例中的微调器之前,您还没有调用setContentView()。
微调器将为null,稍后尝试使用它们会给你NullPointerException。