我在这行中遇到错误mArrayAdapter

我在这行中遇到错误mArrayAdapter

本文介绍了我在这行中遇到错误mArrayAdapter.add(device.getName()+" \ n" + device.getAddress());的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package com.example.i.t;

import java.util.Set;

import android.support.v7.app.ActionBarActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class MainActivity extends ActionBarActivity {

    private static final int REQUEST_ENABLE_BT = 0;
	private static final Set<bluetoothdevice> mArrayAdapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        runfyita();


        runfyitb();

        bluetoothadapter();



    }

private void bluetoothadapter() {
		// TODO Auto-generated method stub

            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

            if (!mBluetoothAdapter.isEnabled())

            {
            	 Intent enableBtIntent = new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE);

            	 startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

            	 Set<bluetoothdevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

            	 if (pairedDevices.size() > 0)
            	 {
            		  for (BluetoothDevice device : pairedDevices)
            		  {
            			mArrayAdapter.add(device.getName() + "\n" + device.getAddress());

            		  }
            	 }


            	 final BroadcastReceiver mReceiver = new BroadcastReceiver() {

					@Override
					public void onReceive(Context context, Intent intent) {
						// TODO Auto-generated method stub

						String action = intent.getAction();

						if (BluetoothDevice.ACTION_FOUND.equals(action))
						{

							BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

							 mArrayAdapter.add(device.getName() + "\n" + device.getAddress());

						}

					}
				};

            }

	}












	private void runfyitb() {
		// TODO Auto-generated method stub

    	Button button = (Button) findViewById(R.id.fyitb);

    	button.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent intent = new Intent (MainActivity.this, Fyitbtimetable.class);

				startActivity(intent);



			}
		});

	}


private void runfyita() {
		// TODO Auto-generated method stub


		Button button = (Button) findViewById(R.id.fyita);

		button.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				Intent intent = new Intent(MainActivity.this, Fyitatimetable.class);

				startActivity(intent);

			}
		});
	}



@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

推荐答案

mArrayAdapter = new Set<bluetoothdevice>;</bluetoothdevice>



之前;


before;

bluetoothadapter();


这篇关于我在这行中遇到错误mArrayAdapter.add(device.getName()+&quot; \ n&quot; + device.getAddress());的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:34