语法错误,插入"}"完成ClassBody [英] Syntax error, insert "}" to complete ClassBody

查看:387
本文介绍了语法错误,插入"}"完成ClassBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习如何编写的Andr​​oid程序。我刚刚读完这本书Android开发者的食谱构建应用程序与Android的SDK。我试着写下列code:

I am currently trying to learn how to to write Android programs. I just finish reading the book "The Android Developer's Cookbook Building Applications with the Android SDK". I tried to write the following code:

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。
我以为我把所有的支架排队。看完这个论坛之后还我要购买书籍专业的Andr​​oid应用程序开发人员。任何帮助将大大AP preciated。

I am getting the following error: Syntax error, insert "}" to complete ClassBody. I thought I had all the bracket line up. Also after reading this forum I am going to purchase the book "Professional Android Application Developer". Any help would be greatly appreciated.

推荐答案

这code:

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

必须出现一个构造函数或方法中。快速浏览,这就是我看到的是错的,但没有承诺没有什么更多的。

Must appear inside a constructor or a method. At a quick glance, that's all I saw was wrong, but no promises there's nothing more.

编辑:

一个方法可能是,这里是有道理实际上,唯一我不好。

A method is probably the only thing that makes sense here actually, my bad.

编辑:

此外,在意见中提到的包东西......好抓@Ted

Also the package thing mentioned in the comments... good catch @Ted

这篇关于语法错误,插入"}"完成ClassBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆