Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java &引用;实例化异常:零参数构造函数“---&燃气轮机;怎么做?_Java_Android_Android Fragments_Service_Instantiationexception - Fatal编程技术网

Java &引用;实例化异常:零参数构造函数“---&燃气轮机;怎么做?

Java &引用;实例化异常:零参数构造函数“---&燃气轮机;怎么做?,java,android,android-fragments,service,instantiationexception,Java,Android,Android Fragments,Service,Instantiationexception,我已经读过有关这方面的文章,但无论如何都找不到解决问题的方法(这里是初学者…) 所以,我目前正在开发一个Android Studio应用程序。 我刚刚做了一些片段,以便在屏幕上有不同的选项卡。 以前我做过一个“蓝牙和蓝牙服务”活动,工作非常出色。 然而,由于我已经实现了这些片段,所以出现了这个错误 java.lang.InstantiationException: java.lang.Class<com.example.thibaud.dogbotapp.bluetoothService

我已经读过有关这方面的文章,但无论如何都找不到解决问题的方法(这里是初学者…) 所以,我目前正在开发一个Android Studio应用程序。 我刚刚做了一些片段,以便在屏幕上有不同的选项卡。 以前我做过一个“蓝牙和蓝牙服务”活动,工作非常出色。 然而,由于我已经实现了这些片段,所以出现了这个错误

 java.lang.InstantiationException: java.lang.Class<com.example.thibaud.dogbotapp.bluetoothService> has no zero argument consde here
此处的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();
    }
}
好的,首先在这里发布抱歉,如果它不完美,希望你们能够帮助!
Thanksar

零参数构造函数声明如下:

public ClassName() {
//Constructor tasks go here
}
希望能有帮助

编辑:


是的,正如davidxxx所说,你应该总是以大写字母开始类名。e、 g.
ClassName
ClassName
相反。但是,变量名以小写开头,比如
variableName

public bluetoothService(){}
类应该以大写开头。嗯,实际上我知道,但是,这是关于我在初始构造函数中的参数,我不知道如何在没有构造函数的情况下初始化它们……如果我正确理解了您的意思(如果没有,请告诉我),那么每个类都必须有一个构造函数(一个空的、零参数的构造函数,最少一个)。没有构造函数的类是不可能存在的。是的,好的,但我如何将其初始化,然后mContext=context;btAdapter=BluetoothAdapter.getDefaultAdapter();start();我理解
上下文
是一个正式参数。根据调用的内容,可能有一种方法可以将
上下文
实例化为变量,该变量可以设置为
mContext
。您可以初始化
btAdapter=BluetoothAdapter.getDefaultAdapter()
start()正常,因为它们不依赖于参数。另外,您能否使用
this
关键字在部分代码中设置
mContext
?这不是任何人都在寻找的答案,我们知道如何创建零参数构造函数。
public ClassName() {
//Constructor tasks go here
}