小编And*_*lov的帖子

Android Espresso:PerformException

我得到了

android.support.test.espresso.PerformException:在视图上执行'send keyCode:4,metaState:0 key event'时出错'目标设备上启用了动画或转换.

我读的文章有相同的错误,但没有找到答案.

我有简单的Android应用程序,我尝试测试简单的事情:

  1. 加载RecyclerView
  2. 单击RecyclerView的项目
  3. 打开活动
  4. 按活动中的按钮
  5. 按下
  6. 从第1部分开始重复

代码非常简单:

@Test
public void getOver500Products() {
    onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
    onView(withId(R.id.layout2)).perform(click());
    clickExactItem(2);
    for (int i = 0; i< 501; i++) {
        clickRandomItem();
        addedToCart();
        Espresso.pressBack();
    }
}

public void clickRandomItem() {
    try {
        int x = getRandomRecyclerPosition(R.id.list);
        clickExactItem(x);
    } catch (NoMatchingViewException e) {
    }
}

public void clickExactItem(int position) {
    onView(withId(R.id.list))
            .perform(RecyclerViewActions
                    .actionOnItemAtPosition(position, click()));
}

public boolean addedToCart() {
    try {
        onView(withId(R.id.product_add_in_cart)).perform(click());
    } catch (NoMatchingViewException e) {
        return false;
    } …
Run Code Online (Sandbox Code Playgroud)

java android android-espresso

21
推荐指数
3
解决办法
9779
查看次数

Kotlin 中实际关键字的目的是什么

我注意到协程的一些函数用actual关键字标记。

文档

实际表示多平台项目中特定于平台的实现

正如我从文档中 了解到的,actual关键字用于多平台项目,应该与expect关键字配对使用。

像这样的东西:

常用模块:

package org.jetbrains.foo

expect class Foo(bar: String) {
    fun frob()
}

fun main(args: Array<String>) {
    Foo("Hello").frob()
}
Run Code Online (Sandbox Code Playgroud)

对应模块:

package org.jetbrains.foo

actual class Foo actual constructor(val bar: String) {
    actual fun frob() {
        println("Frobbing the $bar")
    }
}
Run Code Online (Sandbox Code Playgroud)

那个案子很清楚。

但是在包中kotlinx.coroutines.experimental我注意到有些函数像launch或被withContext标记为actual但是expect包中没有函数。

那么没有actual关键字的目的是什么? expect

kotlin

18
推荐指数
2
解决办法
3834
查看次数

Windows.UI.Notifications丢失

我想在此示例中为Windows 10中的操作中心创建简单的Toast通知.但我在第2步遇到了问题:

using Windows.UI.Notifications;
Run Code Online (Sandbox Code Playgroud)

它失踪了.但是我花了很多时间才找到它而没有结果.我真的不知道我在哪里可以找到或至少下载它.

我尝试了什么:

  1. 漫长的探索后,我发现Windows.UI.dllC:\Windows\System32,但是当我尝试将其添加为引用到项目中,我得到这个错误.即使在我尝试复制它并使其完全可访问之后,也没有任何改变

在此输入图像描述

  1. 我试图重新安装.Net(我使用的是4.5.2)
  2. 安装了Windows 10 SDK
  3. 试图用全球进口
  4. 添加
<PropertyGroup>
      <TargetPlatformVersion>10.0</TargetPlatformVersion>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
  1. 添加了System.Runtime.dll参考

可能对您无用的示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.QueryStringDotNET;
using Windows.UI.Notifications;


namespace MessagerClient.Notifications {
    class DefaultWindowsNotification {

        public static void notificationTest() {
            string title = "Andrew sent you a picture";
            string content = "Check this out, Happy Canyon in Utah!";
            string image = "http://blogs.msdn.com/something.jpg";
            string logo = "ms-appdata:///local/Andrew.jpg";
            ToastVisual …
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

当我尝试从 ViewModel 更改 ModalBottomSheetState 时,MonotonicFrameClock 在此 CoroutineContext 中不可用

我想从 ViewModel 中的 Jetpack Compose 更改 ModalBottomSheet 的状态。

我所做的是,我有一个 ViewModel,如下所示:

class MyViewModel() {
    @ExperimentalMaterialApi
    val bottomSheetDialogState = ModalBottomSheetState(
        initialValue = ModalBottomSheetValue.Hidden
    )

    fun showBottomSheet() {
        viewModelScope.launch {
            bottomSheetDialogState.show()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和内部片段:

@ExperimentalMaterialApi
@Composable
fun ShowUnableToChangeDialog() {
    ModalBottomSheetLayout(
        sheetState = viewModel.bottomSheetDialogState,
        sheetShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp),
        sheetBackgroundColor = Color.White,
        sheetContent = {
            Box(modifier = Modifier.defaultMinSize(minHeight = 1.dp)) {
                Column {
                }
            }
        }
    ) { }
}
Run Code Online (Sandbox Code Playgroud)

当我打电话时,showBottomSheet()我发现了这个异常:

java.lang.IllegalStateException:MonotonicFrameClock 在此 CoroutineContext 中不可用。调用者应使用 withContext 提供适当的 MonotonicFrameClock。在 …

android kotlin android-jetpack-compose

10
推荐指数
1
解决办法
3879
查看次数

使用Okhttp3的OPTIONS/HEAD REST API请求

我在Android上写了一些Rest客户端,我遇到了一个问题 - 我不知道如何制作HEAD和OPTIONS请求.

OkHttp3中的GET/POST/PUT/DELETE/PATCH请求没有问题,基本上它们看起来像:

        request = new Request.Builder()
                .url(url)
                .headers(headerBuilder.build())
                .post(bodyBuilder.build())
                .build();
Run Code Online (Sandbox Code Playgroud)

并且OkHttp3不提供其他方法,如head()或option().

那么如何使用OkHttp3创建HEAD和OPTIONS请求?

java android okhttp okhttp3

6
推荐指数
2
解决办法
1200
查看次数

如何在顶级函数中使用koin注入依赖项

我有顶级功能

fun sendNotification(context:Context, data:Data) {
    ...//a lot of code here
}
Run Code Online (Sandbox Code Playgroud)

该函数创建通知,有时通知可以包含图像,所以我必须下载它.我使用Glide,它被包裹在接口ImageManager上,所以我必须注入它.我使用Koin进行DI,问题是我无法写

val imageManager: ImageManager by inject()
Run Code Online (Sandbox Code Playgroud)

在我的代码中的某个地方,因为没有实现KoinComponent接口的东西.

最明显的解决方案是将已经注入其他地方imageManager作为函数参数传递,但我不想这样做,因为在大多数情况下我不需要imageManager:它取决于Data参数的类型.

kotlin koin

6
推荐指数
1
解决办法
630
查看次数

自定义 Lint 在 Android Studio 中不突出显示

我有我的自定义 lint,它检查 XML 文件的十六进制颜色使用情况。

当我运行时它完美地工作

./gradlew myapp:lint
Run Code Online (Sandbox Code Playgroud)

但它没有突出问题的地方。甚至更多 - Analyze -> Inspect Code不给我结果,只返回

未发现可疑代码。

源代码:

class XmlColorsDetector : ResourceXmlDetector() {

    companion object {
        val ISSUE: Issue = Issue.create(
            id = "CustomColorsXml",
            briefDescription = "Custom colors detector",
            explanation = "Use only theme colors, in other case our themes behaviour will not work properly",
            category = Category.CORRECTNESS,
            priority = 6,
            severity = Severity.ERROR,
            implementation = Implementation(
                XmlColorsDetector::class.java,
                Scope.RESOURCE_FILE_SCOPE
            )
        )
    }

    override fun getApplicableAttributes(): Collection<String>? {
        return listOf("color", "textColor", "background")
    } …
Run Code Online (Sandbox Code Playgroud)

xml android lint android-studio

6
推荐指数
0
解决办法
240
查看次数

如果该位置的视图在屏幕上不可见或滚出,则 Android Recyclerview notifyItemChanged(position ,payLoad) 不起作用

RecyclerView在我的应用程序中使用它有itemViewCache20 个项目,因为我的列表的最大可能大小为 20。它是“单个项目选择列表”。现在当列表加载时,第一个单元格将突出显示为默认选定位置。如果我单击不同位置的单元格,该位置的视图将被选中并突出显示,同时先前选择的视图变为白色,即未选中。以上工作正常,因为我使用adapter.notifyDataSetChanged(position, payLoad)方法更新列表中的数据。但是当当前选定位置的单元格滚动出屏幕并且我尝试选择新位置时,但是新单元格抓住突出显示并被选中,它不会使以前选择的单元格变白。对于滚动出位置的单元格,系统甚至不调用notifyDataSetChanged(positioin, payLoad)在其中制作 ui 的方法。任何帮助将不胜感激,因为我与RecyclerViews.

这是我的适配器的代码:

class EventsCalendarAdapter(var eventSectionedFrag: EventSectionedFrag, var arrayList: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_calendar_months, parent, false)
    return CalendarHolder(view)
}

override fun getItemCount() = arrayList.size


override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>) {
    if (payloads.isNotEmpty()) {
        var bundle = payloads[0] as Bundle
        var isSelected: Boolean? = bundle.getBoolean("selected")
        var setCurrentMonthSelected: Boolean? = bundle.getBoolean("setMonth")


        with(holder) { …
Run Code Online (Sandbox Code Playgroud)

android android-layout kotlin android-recyclerview

5
推荐指数
1
解决办法
4563
查看次数

Koin Android:org.koin.error.NoBeanDefFoundException

收到该消息错误

java.lang.RuntimeException: Unable to create application com.app.name.application.MainApplication: org.koin.error.BeanInstanceCreationException: Can't create bean Bean[class=com.app.name.general.preferences.Preferences] due to error :
    org.koin.error.NoBeanDefFoundException: No definition found to resolve type 'android.app.Application'. Check your module definition
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5830)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1673)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:172)
    at android.app.ActivityThread.main(ActivityThread.java:6637)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: org.koin.error.BeanInstanceCreationException: Can't create bean Bean[class=com.app.name.general.preferences.Preferences] due to error :
    org.koin.error.NoBeanDefFoundException: No definition found to resolve type 'android.app.Application'. Check your module definition
    at org.koin.core.instance.InstanceFactory.createInstance(InstanceFactory.kt:63)
    at org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:26)
    at org.koin.KoinContext$resolveInstance$$inlined$synchronized$lambda$1.invoke(KoinContext.kt:85)
    at org.koin.KoinContext$resolveInstance$$inlined$synchronized$lambda$1.invoke(KoinContext.kt:23)
    at …
Run Code Online (Sandbox Code Playgroud)

android kotlin koin

5
推荐指数
2
解决办法
4082
查看次数

android.os.Looper中的方法myLooper没有用Coroutines嘲笑

我想在JUnit中对协同程序进行一些测试,但我遇到了一些问题.代码很简单:

@Test
fun coroutineTest() {
    //runBlocking(Unconfined) doesnt work too 
    runBlocking () {
        delay(1000)
        println("test")
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到了那个错误

java.lang.RuntimeException: Method myLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.

at android.os.Looper.myLooper(Looper.java)
at kotlinx.coroutines.experimental.android.MainLooperChecker.checkRunBlocking(HandlerContext.kt:124)
at kotlinx.coroutines.experimental.BuildersKt__BuildersKt.runBlocking(Builders.kt:42)
at kotlinx.coroutines.experimental.BuildersKt.runBlocking(Unknown Source)
at app.deadmc.sometests.tests.ExampleUnitTest.coroutineTest(ExampleUnitTest.kt:22)
Run Code Online (Sandbox Code Playgroud)

我想到的第一件事是错误的协程背景.所以我确定使用Unconfined但不起作用.

我试过了

android {
  // ...
  testOptions { 
    unitTests.returnDefaultValues = true
  }
}
Run Code Online (Sandbox Code Playgroud)

但这也不起作用,我得到以下错误:

java.lang.IllegalStateException: runBlocking is not allowed in Android main looper thread
Run Code Online (Sandbox Code Playgroud)

但根本没有Android main looper!

如何在JUnit中运行阻塞协同程序?

junit android kotlin kotlinx.coroutines

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

如何获取整个 git 历史的文件夹大小

我在 git 中有一些文件夹,里面有不同的文件(例如小图像)。图像的每次更改/插入都永远存储在 git 历史记录中。如果该文件夹增长太多,例如它将超过 50mb,则可能会给该 git 存储库的所有用户带来一些问题。

由于某些原因,我不能使用,git-lfs因为它会产生很大的问题。

所以问题是:如何计算历史记录中所有提交中选定目录中所有文件的大小?或者一些想法如何实现它?

git

3
推荐指数
1
解决办法
426
查看次数

动态将 LayoutManager 更改为 FlexboxLayoutManager 时崩溃

我必须同时使用两者LinearLayoutManagerFlexbotLayoutManager取决于 RecyclerView 中孩子的大小。

当我更改LinearLayoutManagerFlexbotLayoutManager动态时:

recyclerView.layoutManager = 
            FlexibleFlexboxLayoutManager(context).apply {
                    flexWrap = FlexWrap.NOWRAP
                    flexDirection = FlexDirection.ROW
            }
Run Code Online (Sandbox Code Playgroud)

我面临这个错误:

java.lang.ClassCastException: android.support.v7.widget.RecyclerView$LayoutParams 无法转换为 com.google.android.flexbox.FlexItem at com.google.android.flexbox.FlexboxHelper.calculateFlexLines(FlexboxHelper.java:439) at com.google.android.flexbox.FlexboxHelper.calculateHorizo​​ntalFlexLines(FlexboxHelper.java:243) 在 com.google.android.flexbox.FlexboxLayoutManager.updateFlexLines(FlexboxLayoutManager.java:955) 在 com.google.android.flexbox.FlexboxLayoutManager.onLayoutChildren( FlexboxLayoutManager.java:731) 在 android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924) 在 android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3336) 在 android.view.View .measure(View.java:22071)

如何解决?

android android-flexboxlayout

0
推荐指数
1
解决办法
971
查看次数