Home > Blockchain >  How do I fix this "class 'application' not abstract" error?
How do I fix this "class 'application' not abstract" error?

Time:05-25

I'm trying to run the example here. It's flutter & I'm trying to run it on an Android emulator. I'm getting an error:

> Task :app:compileDebugKotlin FAILED
[        ] e: /Users/user/flutter-samples/packages/stream_chat_v1/android/app/src/main/kotlin/com/example/example/Application.kt: (10, 1): Class 'Application' is not
abstract and does not implement abstract member public abstract fun registerWith(p0: PluginRegistry): Unit defined in
io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
[    1 ms] e: /Users/user/flutter-samples/packages/stream_chat_v1/android/app/src/main/kotlin/com/example/example/Application.kt: (15, 5): 'registerWith' overrides
nothing
[   95 ms] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] Execution failed for task ':app:compileDebugKotlin'.
[        ] > Compilation error. See log for more details
[        ] * Try:
[        ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[        ] * Get more help at https://help.gradle.org
[        ] BUILD FAILED in 1m 57s

This is the Application.kt file:

package com.example.example

import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin
import io.flutter.plugins.pathprovider.PathProviderPlugin

class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
    }

    override fun registerWith(registry: PluginRegistry?) {
        PathProviderPlugin.registerWith(registry?.registrarFor(
                "io.flutter.plugins.pathprovider.PathProviderPlugin"))
        SharedPreferencesPlugin.registerWith(registry?.registrarFor(
                "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"))
        FlutterLocalNotificationsPlugin.registerWith(registry?.registrarFor(
                "com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
    }
}

I tried looking at other similar answers, but they were all very specific to the functions and codes that those authors were using. What do I do?

CodePudding user response:

What happens is that you have an abstract class PluginRegistrantCallback that your Application class extends from. This abstract class has a method public abstract fun registerWith(p0: PluginRegistry): Unit that you don't implement in Application (if you look closely, it's not the same). What you can do to solve this:

  • If you never use this abstract function, just remove it from the parent class if possible.
  • Implement the above function but leave its body empty.

That should solve the problem. I don't know if that PluginRegistrantCallback is something you made, if so, you may want to edit your override fun registerWith(registry: PluginRegistry?) to override fun registerWith(registry: PluginRegistry), that should solve the problem as well, depending on how the PluginRegistrantCallback is defined (which abstract methods does it have).

You should keep in mind that an abstract class that contains abstract methods means that every time you make a class extend from it, you have to define the abstract methods in it.

CodePudding user response:

You have implemented PluginRegistrantCallback but didn't implement the method of this class.

You have two solution here.

  1. Add implementation of the methods of PluginRegistrantCallback class

  2. Remove PluginRegistrantCallback implemented class.

  • Related