如何从Kotlin中的函数返回3个相同类型(Int)的单独数据值?
我试图返回一天中的时间,我需要将小时,分钟和秒作为单独的整数返回,但是所有这一切都来自同一个函数,这可能吗?
在快速我们这样做,如下,
func getTime() -> (Int, Int, Int) {
...
return ( hour, minute, second)
}
Run Code Online (Sandbox Code Playgroud)
我们可以在Kotlin实现这一目标吗?
PS:我知道我可以使用Array或Hashmap,但我想知道kotlin中是否存在类似于swift的东西.
我实现了一个在外部存储中生成和创建文件的应用程序.你能帮帮我,我们怎么能删除它?
谢谢钱德拉
编辑-1: 我添加了以下代码,但我仍然遇到同样的问题,请看下面的代码,
String fullPath = "/mnt/sdcard/";
System.out.println(fullPath);
try{
File file = new File(fullPath, "audio.mp3");
if(file.exists()){
boolean result = file.delete();
System.out.println("Application able to delete the file and result is: " + result);
// file.delete();
}else{
System.out.println("Application doesn't able to delete the file");
}
}catch (Exception e){
Log.e("App", "Exception while deleting file " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
在LogCat中我得到Application能够删除文件,结果是:false.执行此操作后,我附加了屏幕截图.请仔细看看.并建议我.
我正在按照官方文档将Facebook Ads集成到我的应用程序中。但是当我运行我的应用程序时,出现以下异常
java.lang.IllegalStateException: You can't call show() for ad in state LOADING. You can change Integration Error mode by setting AdSettings.setIntegrationErrorMode()
at com.facebook.ads.internal.c.a.a(Unknown Source:122)
at com.facebook.ads.internal.c.f.a(Unknown Source:6)
at com.facebook.ads.InterstitialAd.show(Unknown Source:2)
at tech.grapegames.pdfreader.ui.MainActivity.moveToFragment(MainActivity.java:115)
at tech.grapegames.pdfreader.ui.HomeFragment.onClick(HomeFragment.java:85)
at android.view.View.performClick(View.java:6897)
at android.view.View$PerformClick.run(View.java:26101)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Run Code Online (Sandbox Code Playgroud)
下面是我的代码
private com.facebook.ads.InterstitialAd fbInterstitialAd;
fbInterstitialAd = new com.facebook.ads.InterstitialAd(this, getString(R.string.fb_interstitial_ad_id));
fbInterstitialAd.loadAd();
Run Code Online (Sandbox Code Playgroud)
我在下面显示它
if (fbInterstitialAd.isAdLoaded() && !fbInterstitialAd.isAdInvalidated()) {
fbInterstitialAd.show();//This line causes the crash
Run Code Online (Sandbox Code Playgroud)
这是我在build.gradle中添加的依赖项
implementation 'com.facebook.android:audience-network-sdk:5.+'
Run Code Online (Sandbox Code Playgroud)