当我尝试运行它时,我的活动崩溃了,这是代码:
public class WifiActivity extends Activity {
private ListView listeViewWifi;
private List<WifiItem> listeWifiItem;
private WifiAdapter wifiAdapter;
private WifiManager wifiManager;
private WifiBroadcastReceiver broadcastReceiver;
private Timer timer;
private Timer timer2;
private boolean success;
private boolean broadcastFinish;
private Button buttonMeasure;
private Button buttonLocate;
private EditText coordX;
private EditText coordY;
private float[][][] radioMap = new float[100][100][5];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi);
listeViewWifi = (ListView) findViewById(R.id.listViewWifi);
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if(wifiManager != null){
wifiManager.startScan();}
// On récupère le service WiFi d'Android
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
// Gestion de la liste des AP WiFi (voir tuto sur les adapters et les
// listviews)
listeWifiItem = new ArrayList<WifiItem>();
wifiAdapter = new WifiAdapter(this, listeWifiItem);
listeViewWifi.setAdapter(wifiAdapter);
// Création du broadcast Receiver
broadcastReceiver = new WifiBroadcastReceiver();
// On attache le receiver au scan result
registerReceiver(broadcastReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
/* timer = new Timer(this);
timer.applyTimer();*/
buttonLocate = (Button) this.findViewById(R.id.buttonLocate);
buttonMeasure = (Button) this.findViewById(R.id.buttonMeasure);
buttonMeasure.setOnClickListener((OnClickListener) this);
buttonLocate.setOnClickListener((OnClickListener) this);
}
// @Override //Error if I write it, and there is a crash if I delete it.
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonMeasure:
coordX = (EditText) findViewById(R.id.coordX);
coordY = (EditText) findViewById(R.id.coordY);
String xString = coordX.getText().toString();
final int xInt = Integer.parseInt(xString);
String yString = coordY.getText().toString();
final int yInt = Integer.parseInt(yString);
timer2 = new Timer(WifiActivity.this);
while(broadcastReceiver.getMeasureFinished()<=49){
Log.d("info7","mesure" + broadcastReceiver.getMeasureFinished());
timer2.applyTimer();
}
for(int i=0;i<=4;i++){
radioMap[xInt][yInt][i]=broadcastReceiver.getRSSI(i);
}
case R.id.buttonLocate:
//localization.
}
}
问题是什么?为什么我不能在 OnClick 事件上写 @Override?我该如何解决?我试图不使用覆盖,但程序崩溃,如果我写它,eclipse会抱怨有一个错误......所以我不知道我该如何继续......
谢谢!