0

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

Thib96
  • 1
  • 1
  • 3

1 Answers1

-1

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.

Gazza732
  • 169
  • 3
  • 15
  • Hum actually I know that but, it's about the arguments I have in my initial constructor, I have no idea of how to initialize them without a constructor... – Thib96 Jun 16 '17 at 19:20
  • If I understand what you mean correctly (let me know if not), then each class **must** have a constructor (an empty, zero-argument one at the minimum). You cannot have a class without a constructor. – Gazza732 Jun 16 '17 at 19:24
  • Yes ok but how could I inisialize that then mContext = context; btAdapter = BluetoothAdapter.getDefaultAdapter(); start(); – Thib96 Jun 16 '17 at 19:36
  • I understand the `context` is a formal argument. Depending on what is being called there may be a way to instantiate `context` to a variable which could be set as `mContext`. You could initialize `btAdapter = BluetoothAdapter.getDefaultAdapter();` `start();` as normal because they are not reliant on an argument. Also, could you use the `this` keyword for setting `mContext` in part of your code? – Gazza732 Jun 16 '17 at 20:19
  • This is not the answer anybody is looking for, we know how to create a zero arg constructor. – as2d3 Jun 17 '21 at 15:19