"InstantiationException: zero argument constructor" ---> How to do it?

4.3k views Asked by At

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. 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. 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 :

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 :

 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

1

There are 1 answers

5
Gazza732 On

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. e.g. ClassName as opposed to className. Variable names, however, start with lower case such as variableName.