gpt4 book ai didi

android - 语法错误,插入 "}"完成ClassBody

转载 作者:行者123 更新时间:2023-11-30 04:33:31 24 4
gpt4 key购买 nike

我目前正在尝试学习如何编写 Android 程序。我刚刚读完“Android 开发人员的 Cookbook 使用 Android SDK 构建应用程序”一书。我试着写了下面的代码:

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。我以为我把所有的括号都排好了。同样在阅读了这个论坛之后,我打算购买“Professional Android Application Developer”这本书。任何帮助将不胜感激。

最佳答案

这段代码:

     registerReceiver(mReceiver, filter);
myBluetooth.startDiscover();

必须出现在构造函数或方法中。乍一看,我只看到了错误,但没有保证没有更多。

编辑:

方法可能是这里唯一有意义的东西,我的错。

编辑:

还有评论中提到的包的东西......好 catch @Ted

关于android - 语法错误,插入 "}"完成ClassBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7265072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com