[英]“InstantiationException: zero argument constructor” ---> How to do it?
I have already read things about that but can't find a way to fix my problem anyway (Beginner here...) So, I'm currently developping an Android Studio App. 我已经读过有关此内容,但无论如何都找不到解决我的问题的方法(在这里是初学者...)因此,我目前正在开发一个Android Studio应用程序。 I have just done fragments to have different tab on a screen.
我刚刚完成了片段操作,以便在屏幕上显示不同的标签。 Previously I have done a "bluetooth and a bluetoothService" activity who was perfectly working.
以前,我已经完成了一个“蓝牙和bluetoothService”活动,该活动运行得很好。 However, since I have implements these fragments I got this error
但是,由于我已经实现了这些片段,所以出现了此错误
java.lang.InstantiationException: java.lang.Class<com.example.thibaud.dogbotapp.bluetoothService> has no zero argument consde here
So I have tried to do an empty constructor but I don't know how to do it properly... 所以我试图做一个空的构造函数,但是我不知道如何正确地做...
This is the begin of my bluetoothService class : 这是我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() method 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();
}
}
Well, first post here sorry if it's not perfect, hope you guys will be able to help ! 好吧,在这里先发帖抱歉,如果它还不够完善,希望你们能够为您提供帮助! Thanksar
Thanksar
A zero-argument constructor is declared like so: 零参数构造函数的声明如下:
public ClassName() {
//Constructor tasks go here
}
Hope it helps 希望能帮助到你
EDIT: 编辑:
And yes, as davidxxx stated, you should always start class names with upper case letters. 是的,正如davidxxx所说,您应该始终以大写字母开头类名。 eg
ClassName
as opposed to className
. 例如
ClassName
而不是className
。 Variable names, however, start with lower case such as variableName
. 但是,变量名以小写开头,例如
variableName
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.