![](/img/trans.png)
[英]java.lang.InstantiationException: class has no zero argument constructor error
[英]“InstantiationException: zero argument constructor” ---> How to do it?
我已经读过有关此内容,但无论如何都找不到解决我的问题的方法(在这里是初学者...)因此,我目前正在开发一个Android Studio应用程序。 我刚刚完成了片段操作,以便在屏幕上显示不同的标签。 以前,我已经完成了一个“蓝牙和bluetoothService”活动,该活动运行得很好。 但是,由于我已经实现了这些片段,所以出现了此错误
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();
}
}
好吧,在这里先发帖抱歉,如果它还不够完善,希望你们能够为您提供帮助! Thanksar
零参数构造函数的声明如下:
public ClassName() {
//Constructor tasks go here
}
希望能帮助到你
编辑:
是的,正如davidxxx所说,您应该始终以大写字母开头类名。 例如ClassName
而不是className
。 但是,变量名以小写开头,例如variableName
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.