我目前正在學習如何編寫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'。 –