小编jo *_* jo的帖子

java代码中使用kotlin时void无法转换为Unit - android

我正在我的项目中一起工作kotlin,我有一个如下所示的java课程:kotlin

class AuthenticationPresenter @Inject constructor(
    private val navigator: AuthenticationNavigator,
    private val getCurrentServerInteractor: GetCurrentServerInteractor,
    private val getAccountInteractor: GetAccountInteractor,
    private val settingsRepository: SettingsRepository,
    private val localRepository: LocalRepository,
    private val tokenRepository: TokenRepository
) {
    suspend fun loadCredentials(newServer: Boolean, callback: (authenticated: Boolean) -> Unit) {
        val currentServer = getCurrentServerInteractor.get()
        val serverToken = currentServer?.let { tokenRepository.get(currentServer) }
        val settings = currentServer?.let { settingsRepository.get(currentServer) }
        val account = currentServer?.let { getAccountInteractor.get(currentServer) }

        account?.let {
            localRepository.save(LocalRepository.CURRENT_USERNAME_KEY, account.userName)
        }

        if (newServer || currentServer …
Run Code Online (Sandbox Code Playgroud)

java android kotlin

8
推荐指数
2
解决办法
4779
查看次数

':app'无法在当前上下文中执行 - android studio 3.2.1

我在我的项目中使用OneSignal,如下:

def taskRequests = getGradle().getStartParameter().getTaskRequests().toString()
def isPlay = !(taskRequests.contains("Foss") || taskRequests.contains("foss"))
buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
    maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
if (isPlay) {
    apply plugin: 'io.fabric'
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "com.github.ben-manes.versions"

android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools

    defaultConfig {
        manifestPlaceholders = [onesignal_app_id               : “111”,
                                // Project number pulled from dashboard, …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-gradle-plugin onesignal

8
推荐指数
1
解决办法
4499
查看次数

Kotlin - 类型不匹配所需的集合找到列表

我需要附加两个list,但它告诉我:

type mismatch required collection found list
Run Code Online (Sandbox Code Playgroud)

就像下面这样:

val list: List<Cohort> = ArrayList()
private fun fillFromDao() {
    val notesObserver: Observer<ArrayList<Cohort?>?>? =
        Observer { cohort: ArrayList<Cohort?>? ->
                list.toMutableList().addAll(cohort)
        }
    if (notesObserver != null) {
        otherDialogFragmentViewModel.fetchIsFree()?.observe(this, notesObserver)
        otherDialogFragmentViewModel.fetchHasCertificate()?.observe(this, notesObserver)
    }
}
Run Code Online (Sandbox Code Playgroud)

android kotlin

8
推荐指数
1
解决办法
1万
查看次数

膨胀类com.google.android.material.appbar.AppBarLayout时出错

我有吼叫xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:elevation="0dp">
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbarMainActivity"
                style="@style/CustomToolbar"
                android:background="@color/biscay"
                app:layout_scrollFlags="scroll|enterAlways">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageButton
                        android:id="@+id/icon_drawer_imagebutton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:background="@null"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        app:srcCompat="@drawable/ic_drawer" />

                    <RelativeLayout
                        android:gravity="center_horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                     android:layout_toLeftOf="@+id/icon_drawer_imagebutton">

                        <ImageButton
                            android:id="@+id/icon_logo_imagebutton"
                            android:layout_width="@dimen/size_logo"
                            android:layout_height="@dimen/size_logo"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:adjustViewBounds="true"
                            android:background="@null"
                            android:scaleType="fitXY"
                            app:srcCompat="@drawable/ic_logo_white" />

                        <TextView
                            android:id="@+id/nameUniversity_textview"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_centerHorizontal="true"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:textSize="18sp"
                         android:layout_toLeftOf="@+id/icon_logo_imagebutton"
                            android:gravity="center_vertical"
                            android:text="@string/nameUniversity"
                            android:textColor="@color/colorTextLight"
                            android:textStyle="bold" />
                    </RelativeLayout>
                </RelativeLayout>
            </androidx.appcompat.widget.Toolbar>
        </com.google.android.material.appbar.AppBarLayout>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabsMainActivity"
            style="@style/CustomTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-support-design android-appbarlayout

7
推荐指数
2
解决办法
7655
查看次数

在 recyclerView 中使用滑动触摸监听器时,指定为非 null 的错误参数为 null - Android

我使用下面的方法class进行swipe检测recyclerView

open class OnSwipeTouchListener(context: Context) : View.OnTouchListener {
    var context: Context? = context

    private val gestureDetector = GestureDetector(context, GestureListener())

    fun onTouchs(event: MotionEvent): Boolean {
        return gestureDetector.onTouchEvent(event)
    }

    private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {

        private val SWIPE_THRESHOLD = 100
        private val SWIPE_VELOCITY_THRESHOLD = 100

        override fun onDown(e: MotionEvent): Boolean {
            return true
        }

        override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
            onTouchs(e)
            return true
        }


        override fun onFling(@NonNull e1: MotionEvent,
                             @NonNull e2: MotionEvent,
                             @NonNull velocityX: Float, …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview android-swipe

7
推荐指数
1
解决办法
1793
查看次数

Android studio3.3 variantOutput.getProcessResources()已过时,并已替换为'variantOutput.getProcessResourcesProvider()

什么是波纹管警告:

WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
Run Code Online (Sandbox Code Playgroud)

android gradle

7
推荐指数
1
解决办法
9986
查看次数

在android studio中创建dependency.gradle

我如何dependencies.gradle在 android studio 中创建如下所示:

在此输入图像描述

和:

在此输入图像描述

android gradle android-studio gradle-dependencies

4
推荐指数
1
解决办法
2062
查看次数