eclipse UUID无法解析错误

slsn1g29  于 2022-11-04  发布在  Eclipse
关注(0)|答案(2)|浏览(281)

又来了...
我正在尝试创建蓝牙连接,我已经有设备的MAC地址,但当我使用createInsecureRfcommSocketToServiceRecord时,它给了我一个UUID错误...有人知道这是为什么吗?...我提前感谢帮助.
主要内容如下:

package com.example.mustangsound;

//import java.util.UUID;
import java.util.Set;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainActivity extends Activity {

    String toastText = "";
    private BluetoothDevice btDevice;
    private BluetoothSocket btSocket;
    private String btAddress = "11:22:33:44:44:44";
    String mArrayAdapter = "";
    private BluetoothAdapter mBluetoothAdapter = null;

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

    public void BTConnect (View v){

        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null) {
            Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
            finish();
            return;
        }
        else{

            toastText="Connecting to Mustang Sound Bluetooth receiver.... please wait";
            Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();
            BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(btAddress);
            btSocket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("0000111F-0000-1000-8000-00805F9B34FB"));
            btSocket.connect();

        }

    }

    public void LightsOn (View v){

        toastText="Sounds Lights On";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

    public void LightsOff (View v){

        toastText="Sounds Lights Off";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

    public void DoorsOpen (View v){

        toastText="Opening Sound doors";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

    public void DoorsClose (View v){

        toastText="Closing Sound doors";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

    public void SysOn (View v){

        toastText="IT'S ALIVE!!!!!.....IT'S ALIIIIIVEEEEEE";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

    public void SysOff (View v){

        toastText="Mustnag Sound OFF";
        Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();

    }

}
72qzrwbm

72qzrwbm1#

似乎AndroidStudio/IntelliJ在某个地方有一个bug,所以java util jar没有被添加到编译类路径中。具有讽刺意味的是,当输入import语句时,自动完成功能正常工作。奇怪的是,在你的情况下,对于java.util.Set,它工作了。Set可能在其他地方可用,而我在java.util.Date上遇到了同样的问题。
对我来说,这发生在一个全新的项目上,但解决方案是退出AndroidStudio,删除.iml文件和.idea目录,然后重新打开项目。

fykwrbwg

fykwrbwg2#

是,重启IntelliJ后,问题得到解决。这适用于2022 IntelliJ版本。

相关问题