0

我已经阅读过相关内容,但无论如何都找不到解决问题的方法(这里是初学者......)所以,我目前正在开发一个 Android Studio 应用程序。我刚刚完成了片段以在屏幕上显示不同的选项卡。以前我做过一个“蓝牙和蓝牙服务”活动,效果很好。但是,因为我已经实现了这些片段,所以我收到了这个错误

 java.lang.InstantiationException: java.lang.Class<com.example.thibaud.dogbotapp.bluetoothService> has no zero argument consde here

所以我试图做一个空的构造函数,但我不知道如何正确地做......

这是我的 bluetoothService 类的开始:

public class bluetoothService  {


private static final String TAG = "bluetoothService";

private static final String appName = "DogBot";

private static final UUID MY_UUID_INSECURE =
        UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

private final BluetoothAdapter btAdapter;



Context mContext;

private AcceptThread mInsecureAcceptThread;

private ConnectThread mConnectThread;
private BluetoothDevice mmDevice;
private UUID deviceUUID;
ProgressDialog mProgressDialog;

private ConnectedThread mConnectedThread;


/*public bluetoothService(Context context) {
    mContext = context;
    btAdapter = BluetoothAdapter.getDefaultAdapter();
    start();
}*/

start() 方法在这里:

 public synchronized void start() {
    Log.d(TAG, "start");

    // Cancel any thread attempting to make a connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }
    if (mInsecureAcceptThread == null) {
        mInsecureAcceptThread = new AcceptThread();
        mInsecureAcceptThread.start();
    }
}

好吧,第一次在这里发帖,如果不完美,希望你们能提供帮助!谢谢

4

1 回答 1

-1

一个零参数的构造函数声明如下:

public ClassName() {
//Constructor tasks go here
}

希望能帮助到你

编辑:

是的,正如 davidxxx 所说,您应该始终以大写字母开头的类名。例如ClassName,相对于className. 但是,变量名称以小写字母开头,例如variableName.

于 2017-06-16T19:04:15.220 回答