Home > front end >  Unable to create service ... has no zero argument constructor
Unable to create service ... has no zero argument constructor

Time:07-30

Here is my class (the first parts of it, anyway.):

    public class FirebaseService extends FirebaseMessagingService implements TobCommInterface
{
    private static final int TICK_RATE_ALERT_SERVICE = 100;
    private static final int TIMEOUT = 5000;
    private static final int MESSAGE_BUFFER_SIZE = 10240;

    private static final String TAG = "LAUNCH_ATTACK_ALERTS";
    private static final String CHANNEL_ID = "default";

    private static final long[] VIBRATE = new long[]{ 0, 2000, 400, 400, 400, 400, 400, 400 };

    private Context context;

    private enum State
    {
        CONNECT,
        CONNECTING,
        PROCESS
    }

    private Socket socket;
    private InputStream in;
    private OutputStream out;

    private ShortDelay dlyTimeout = new ShortDelay();
    private long oIdleTime;

    private TobComm tobComm;

    private State state = State.CONNECT;

    private static int lDebugInstance = 0;

    private ScheduledExecutorService seCommsService;

    public FirebaseService(Context context)
    {
        this.context = context;
    }

Here is the error I am getting in the logcat:

java.lang.RuntimeException: Unable to create service com.apps.fast.launch.notifications.FirebaseService: java.lang.InstantiationException: java.lang.Class<com.apps.fast.launch.notifications.FirebaseService> has no zero argument constructor

I have heard that the AndroidManifest.xml could be involved with this error as well, so here is the FirebaseMessaging entry in it:

<service
             android:name=".notifications.FirebaseService"
             android:exported="false">
             <intent-filter>
                 <action android:name="com.google.firebase.MESSAGING_EVENT" />
             </intent-filter>
         </service>

I am far from an expert in any of this and currently I am just trying to get Firebase Messaging working for my game. When I open the app, it immediately crashes with this error. When I restart the app, it does not crash.

CodePudding user response:

Delete:

    public FirebaseService(Context context)
    {
        this.context = context;
    }

That's your problem. And you do not need it; a Service is a Context.

  • Related