Android Question (Solved) error: no suitable method found for onCreate(no arguments)

Similar threads

B4A Library HMS - Huawei SDK
B4A Tutorial Inline Java Code
B4A Tutorial Integrating Firebase Services
B4A Library HMS (Huawei) - DRM verification
B4A Library HMS - In App Purchases

Ferdari

Active Member
Licensed User
Hi everyone, again me,

Im integrating the Huawei SDK and Analytics Kit, added all the JARS needed, and using this Java Inline code on Main:

B4X:
    '--------------------HUAWEI SERVICES -----------------------
#if Java

import com.huawei.hms.analytics.HiAnalytics;
import com.huawei.hms.analytics.HiAnalyticsInstance;
import com.huawei.hms.analytics.HiAnalyticsTools;
import com.huawei.agconnect.config.AGConnectServicesConfig;
import com.huawei.agconnect.config.LazyInputStream;
import static com.huawei.hms.analytics.type.HAEventType.*;
import static com.huawei.hms.analytics.type.HAParamType.*;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import java.io.InputStream;
import java.io.IOException;

public class MyApplication extends main{

    public void onCreate() {
        super.onCreate();
    }

    protected void attachBaseContext() {
        Context context = this;
        super.attachBaseContext(context);
        AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
        config.overlayWith(new LazyInputStream(context) {
            public InputStream get(Context context) {
                try {
                    return context.getAssets().open("agconnect-services.json");
                } catch (IOException e) {
                    return null;
                }
            }
        });
    }
    // TODO: End
}

    public void initHMS(){
         HiAnalyticsInstance instance;
        // TODO: Initiate Analytics Kit
        // Enable Analytics Kit Log
        HiAnalyticsTools.enableLog();
        // Generate the Analytics Instance
        instance = HiAnalytics.getInstance(this);
        // You can also use Context initialization
        // Context context = this.getApplicationContext();
        // instance = HiAnalytics.getInstance(context);

        // Enable collection capability
        instance.setAnalyticsEnabled(true);
        // Enable Automatically collection capability
        instance.setAutoCollectionEnabled(true);

        // TODO: Registering the HMS Service
        // Register the HMS service and collect automatic events (account event or InAppPurchase event).
        // Automatic account event collection requires HMS APK 4.0.0.300 or a later version.
        instance.regHmsSvcEvent();
   
    }

#End If
Then i call the Methods here:
B4X:
    NativeMe.InitializeContext
    Log("attachBaseContext...")
    NativeMe.RunMethod("attachBaseContext",Null) 'This is to set the configuration file [I][U]agconnect-services.json[/U][/I]
    Log("initHMS...")
    NativeMe.RunMethod("initHMS", Null)
The app works if i dont call the method NativeMe.RunMethod("attachBaseContext",Null)
But this method is needed to read the file agconnect-services.json, if i don't call it, the library loads OK but says no config file loaded, so it dont work.

The error thrown:

B4X:
B4A Version: 9.80
Java Version: 8
Parsing code.    (0.09s)
Building folders structure.    (0.04s)
Compiling code.    (0.40s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.00s)
Compiling generated Java code.    Error
B4A line: 1065
End Sub
javac 1.8.0_231
src\stickers\memetflix\main.java:2248: error: no suitable method found for onCreate(no arguments)
        super.onCreate();
             ^
    method Activity.onCreate(Bundle) is not applicable
      (actual and formal argument lists differ in length)
    method Activity.onCreate(Bundle,PersistableBundle) is not applicable
      (actual and formal argument lists differ in length)
    method main.onCreate(Bundle) is not applicable
      (actual and formal argument lists differ in length)
Im using the integration tutorial:
Step 5 The Eclipse IDE does not support the AppGallery Connect plug-in. Therefore, you need to place the agconnect-services.json file in the assets directory of your project and add the following code to the Application subclass of the project. If the project does not have an Application subclass, you need to create a subclass that is inherited from the Application subclass. For example, create a MyApplication class.

  1. public class MyApplication extends Application{
  2. @Override
  3. public void onCreate() {
  4. super.onCreate();
  5. }
  6. // TODO: Add the following code:
  7. @Override
  8. protected void attachBaseContext(Context context) {
  9. super.attachBaseContext(context);
  10. AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
  11. config.overlayWith(new LazyInputStream(context) {
  12. public InputStream get(Context context) {
  13. try {
  14. return context.getAssets().open("agconnect-services.json");
  15. } catch (IOException e) {
  16. return null;
  17. }
  18. }
  19. });
  20. }
  21. // TODO: End
  22. }
Is there any other way that i can use to set and read the "agconnect-services.json" on AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);

I spent more than 3 hours realizing what is the problem, help are very appreciated! :D
 
Last edited:

Ferdari

Active Member
Licensed User
I solved it deleteing the onCreate() and the super declaration. it worked!
 
Top