我在我的 android 项目中复制了蓝牙代码,但它显示无法解析到字段的错误

I copied the bluetooth code in my android project but it is showing error that cannot be resolved to a field

我在我的 android 项目中复制了蓝牙代码,但它显示无法解析到字段的错误:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.option_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent serverIntent = null;
    switch (item.getItemId()) {
    case R.id.connect_scan:
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
        return true;
    case R.id.discoverable:
        // Ensure this device is discoverable by others
        ensureDiscoverable();
        return true;
    }
    return false;
}

它向您显示该错误,因为

  • 您可能忘记复制 option_menu.xml 或没有正确复制
  • 您需要重建项目