小编Tak*_*aki的帖子

抑制:kotlinx.coroutines.DiagnosticCoroutineContextException:

我正在使用 jetpack compose 制作一个待办事项应用程序,我可以添加待办事项,但是当从数据库获取它们时,我收到了与 Courtine 相关的错误,但我无法得到,我需要帮助,谢谢

  • 获取数据时抛出错误
       Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@4c0bd0e, androidx.compose.ui.platform.MotionDurationScaleImpl@67ef32f, StandaloneCoroutine{Cancelling}@7800d3c, AndroidUiDispatcher@df61ac5]

Run Code Online (Sandbox Code Playgroud)
  • ViewModel获取数据方法
     fun showTasks() = viewModelScope.launch {
        try {
            dataState = dataState.copy(loading = true)
            todoRepository.getTasks().collectLatest {
                dataState = if(it != null){
                    dataState.copy(data = it)
                } else {
                    dataState.copy(error = "List is empty ...")
                }
            }
        }catch (ex  : Exception){
             dataState = dataState.copy(error = ex.localizedMessage)
        } finally {
             dataState = dataState.copy(loading = false)
        }
    }

Run Code Online (Sandbox Code Playgroud)
  • 在屏幕上显示数据
   @Composable
fun HomeScreen(navController: NavController,
               todoViewModel: TodoViewModel = hiltViewModel()
) {

    val state = …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-viewmodel android-jetpack-compose

9
推荐指数
0
解决办法
3268
查看次数

可组合调用只能在 @Composable 函数的上下文中发生

我有一个可组合函数,我需要在单击按钮后调用它,但它一直显示错误,无法通过单击按钮执行可组合项,任何人都可以指导我解决此问题吗?谢谢

  • 这是我的代码
  Box(contentAlignment = Alignment.Center) {
               Button(onClick = {
                    // This is a composable function that i need to call
                    SignUpNewUser(email,fullName,country,password)
                }
                ,modifier = Modifier
                       .width(200.dp)
                       .background(color = Color.DarkGray)) {
                Text(text = "Sign Up",style = TextStyle(color = Color.White,fontWeight = FontWeight.Bold))
            }
        }
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose

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

在首选项设置中扩展布局

我有一个自定义布局,它有一个 textview 和 ratingbar,然后我将布局设置为我的首选项视图,问题是我试图在我的首选项片段中扩展视图并将 ratingbar 设置为 onclick,我放了一个日志来查看如果它被点击但没有发生任何事情

  • 这是我的偏好
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Preference
        android:title="@string/YourPreferredLanguage"
        android:icon="@drawable/ic_baseline_language_24" />

    <CheckBoxPreference
        android:title="@string/french"
        android:key="french"
        />
   
    <CheckBoxPreference
        android:title="@string/portuguese"
        android:key="portuguese"
        />

    <Preference
        android:title="Rate Our App"
        android:icon="@drawable/ic_baseline_stars_24"
        />

    <PreferenceCategory
        android:layout="@layout/ratinglayout"/> //this is my custom layout

</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
  • 这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/ratingtext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="75dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="20dp"
        android:text="Rate "
        android:textColor="@android:color/black"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:numStars="0"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.75"
        app:layout_constraintStart_toEndOf="@+id/ratingtext"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

*我如何实现它的代码片段

class SettingsFragment : …
Run Code Online (Sandbox Code Playgroud)

android preferences

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

Espresso 测试未在 Android Studio 中运行

我正在 android studio 中为我的应用程序进行一些 espresso 测试,它正在工作并突然停止工作,基本上测试构建并启动,但它卡在测试结果中并且什么也不显示,我的意思是它显示没有测试通过。如果有人可以帮助我,我将不胜感激,谢谢

  • 这是我的 android studio 的屏幕截图(它显示启动成功但测试未开始)

在此输入图像描述

android kotlin android-studio android-espresso

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

用于从导航器推送或弹出路由的上下文必须是导航器小部件的后代小部件的上下文

我正在尝试从第一个屏幕导航到另一个屏幕,所以基本上,我正在检查用户是否已登录,并根据该情况导航或不导航到下一个屏幕,但我收到以下错误尝试时的上下文

这是我的代码

Future _AuthenticateUser(BuildContext context){
  FirebaseAuth.instance
      .authStateChanges()
      .listen((event) {
      if(event == null){
      // User is null
     } else {

        // here I navigate to the next screen
        Navigator.push(context,
            MaterialPageRoute(builder: (context) => new MainScreen()));

    }
  });
}
Run Code Online (Sandbox Code Playgroud)

我首先调用代码来检查用户登录状态

 @override
  void didChangeDependencies() {
    _AuthenticateUser(context);
    super.didChangeDependencies();

  }
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误

The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
Run Code Online (Sandbox Code Playgroud)

flutter

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

Espresso 在 TextInputLayout 中输入一些文本时出错

我想测试我的登录 UI,其中包含一些 TextInputLayout 字段,我已经设置了一些要运行的代码,但它崩溃并引发错误,任何人都可以解决这个问题,我提前表示感谢

  • 我想简单地在 TextInputLayout 中输入一些文本
    @Test
    fun testCaseSimulateLoginOnButtonClick(){
        onView(withId(R.id.loginEmail)).perform(typeText("xxxxxxxx@gmail.com"))
        onView(withId(R.id.loginPassword)).perform(typeText("123456"))
        onView(withId(R.id.loginBtn)).perform(click())
        onView(withId(R.id.drawer)).check(matches(isDisplayed()))
    }
Run Code Online (Sandbox Code Playgroud)
  • 这是我得到的错误
Error performing 'type text(xxxxxxxx@gmail.com)' on view 'view.getId() is <2131362123/com.example.app:id/loginEmail>'.
Run Code Online (Sandbox Code Playgroud)

android kotlin android-espresso

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

java.lang.AssertionError: CALL 'public final fun &lt;get-currentComposer&gt;

我正在尝试使用 jetPack Compose 创建一个项目,我有所有必要的依赖项才能使其工作,但是当我运行我的应用程序时,它抛出一个错误,我找不到解决方案

  • 这是错误:
 java.lang.AssertionError: CALL 'public final fun <get-currentComposer> (): androidx.compose.runtime.Composer<*> declared in androidx.compose.runtime.ComposerKt' type=androidx.compose.runtime.Composer<*> origin=FOR_LOOP_ITERATOR
Run Code Online (Sandbox Code Playgroud)
  • 我添加的所有依赖项

 def jetpackDef = "1.0.0-alpha09"


  // Jetpack compose navigation
        implementation "androidx.navigation:navigation-compose:1.0.0-alpha04"

implementation "androidx.compose.ui:ui:$jetpackDef"
        // Tooling support (Previews, etc.)
        implementation "androidx.compose.ui:ui-tooling:$jetpackDef"
        // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
        implementation "androidx.compose.foundation:foundation:$jetpackDef"
        // Material Design
        implementation "androidx.compose.material:material:$jetpackDef"
        // Material design icons
        implementation "androidx.compose.material:material-icons-core:$jetpackDef"
        implementation "androidx.compose.material:material-icons-extended:$jetpackDef"
        // Integration with observables
        implementation "androidx.compose.runtime:runtime-livedata:$jetpackDef"
        implementation "androidx.compose.runtime:runtime-rxjava2:$jetpackDef"
        implementation "androidx.compose.runtime:runtime:$jetpackDef"


     buildFeatures {
        // Enables Jetpack Compose for …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose

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

从 dataStore 首选项返回 int 值

我有一个应用程序,我int使用数据存储首选项保存值,当我获取值时,我执行代码并希望返回该int值,以便我可以在代码中的不同位置使用它,但无法弄清楚,如果任何人都可以帮忙,提前谢谢你

我尝试创建一个全局成员来分配该值然后返回,但由于该值是异步返回的,因此它使应用程序崩溃。

  • 这是我的代码
private fun setTextSize() : Int {
        val dataStore = requireContext().createDataStore("textSize")
        lifecycleScope.launch { 
            dataStore.data.collect { 
              val textSize =  it[Common.TEXT_SIZE_PREFERENCE] 
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

android datastore kotlin

3
推荐指数
2
解决办法
2994
查看次数

通过改造调用添加多个@Path

我有一个 api 请求,在 url 中我需要传递多个 @Path,我这样做了,但我不断收到错误,我想获得有关此问题的一些帮助,提前谢谢


  @Singleton
  @Provides
  fun provideRetrofitInstance(): ApiInterface {
      val httpLoggingInterceptor = HttpLoggingInterceptor()
      val interceptor = httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC)
      val okHttp = OkHttpClient.Builder()
              .addInterceptor(interceptor)
              .build()
      return Retrofit.Builder()
              .baseUrl("https://api.site.dev/api/v2/entries/")
              .addConverterFactory(GsonConverterFactory.create())
              .client(okHttp)
              .build()
              .create(ApiInterface::class.java)
  }

Run Code Online (Sandbox Code Playgroud)
  • 这是我的改造电话
 Error Unable to create call adapter for class com.dic.mydictionnary.models.DictionnaryModelItem
       for method ApiInterface.getDictionnaryWord
Run Code Online (Sandbox Code Playgroud)

*这是我的apiInterfac

@GET("{language_code}/{word}")
   fun getDictionnaryWord(
           @Path("language_code") language : String,
           @Path("word") word : String,
   ) : DictionnaryModelItem

}
Run Code Online (Sandbox Code Playgroud)

android kotlin retrofit

2
推荐指数
1
解决办法
2132
查看次数