我目前正在学习如何编写Android程序。我刚读完“Android开发人员的食谱用Android SDK构建应用程序”一书。我试图写下面的代码:语法错误,插入“}”完成ClassBody
Package src.com.cookbook.BlueToothSample;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class BlueToothExampleActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// button
Button startBTButton = (Button) findViewById (R.id.Start_BT);
startBTButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
startBlueTooth();
}
});
}
private void startBlueTooth()
{
Intent enableIntent = new Intent(BluetoothAdapter
.ACTION_REQUEST_ENABLE);
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String acton = intent.getAction();
//When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(
BluetoothDevice.EXTRA_DEVICE);
Log.v("BlueTooth Testing", device.getName() + '\n'
+ device.getAddress());
}
}
};
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
myBluetooth.startDiscover();
}
我收到以下错误:语法错误,插入“}”以完成ClassBody。 我以为我把所有的支架排队。在阅读本论坛后,我将购买“专业Android应用程序开发人员”一书。任何帮助将不胜感激。
我不确定这是错误消息的原因,但代码中的第一个单词应该是'package',而不是'Package'。 –