Reputation: 597
I am trying to use a remote service to build a BlueTooth Chat (like the one of the Android Samples). But since my last modifications, the application does not start and the log shows the error no empty constructor
for my service. I have read this post but I cant add any empty constructor. There must be something I do wrong, or maybe it doesnt work for remote services.
This is my constructor :
public RemoteService(Context context, Handler handler) {
mAdapter = BluetoothAdapter.getDefaultAdapter();
mState = STATE_NONE;
}
Can someone tell me what is wrong with it?
Upvotes: 1
Views: 1265
Reputation: 597
Thanks for your answers, but meanwhile, someone helped me and cleaned the code, removing the constructor and doing some other things, but I didn't understand everything.
I am sorry I can't explain exactly what was wrong, but I can say that a non argument constructor was generating errors.
Upvotes: 0
Reputation: 12754
You have to provide default constructor as the service demands a default constructor and then you can use parametrized constructor as you have done.
public class ReminderService extends IntentService {
----------------------------
public ReminderService() // Need to add the default constructor
{
super("ReminderService"); // Calling the super constructor
}
public RemoteService(Context context, Handler handler) //Then use your own constructor
{
mAdapter = BluetoothAdapter.getDefaultAdapter();
mState = STATE_NONE;
}
----------------------------------
}
Try this one and let me know if you still have any issue.
Upvotes: 0
Reputation: 6463
try:
public RemoteService() {
super();
}
Unless your business rules states you can't really have an empty constructor. Then you're calling for a new RemoteService()
somewhere, when you shouldn't.
Upvotes: 1