Skip to content

Not working on Android #11

@customautosys

Description

@customautosys

I marked my method @async and didn't call it in a lambda or anonymous class but still got the following error:

java.lang.UnsupportedOperationException: The method "JPromise#await" should be invoked in an async method. An async method is a method annotated with @JAsync and returning the JPromise object. The method should not be a lambda method or in an anonymous class
	at io.github.vipcxj.jasync.reactive.ReactorPromise.await(ReactorPromise.java:450)

Relevant code below:

@Async
public void loadAd(){
	try{
		AdManager.instance().interstitial().await();
		...
	}catch(Exception e){
		e.printStackTrace();
	}
}

public class AdManager extends com.customautosys.tuxfight.AdManager{
	@Override
	public JPromise<Void> interstitial(){
		if(AndroidLauncher.getInstance().adView==null) return JAsync.error(new Exception("AdMob not loaded yet"));
		return Promises.from(Mono.create(monoSink->AndroidLauncher.getInstance().runOnUiThread(()->InterstitialAd.load(
			AndroidLauncher.getInstance(),
			BuildConfig.DEBUG?"ca-app-pub-...":"ca-app-pub-...",
			new AdRequest.Builder().build(),
			new InterstitialAdLoadCallback(){
				@Override
				public void onAdLoaded(@NonNull InterstitialAd interstitialAd){
					interstitialAd.show(AndroidLauncher.getInstance());
					monoSink.success();
				}

				@Override
				public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){
					monoSink.error(new Exception(loadAdError.getMessage()));
				}
			}
		))));
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions